自己尝试着扩展.Net的RichTextBox控件,能够实现插入QQ表情,
1. 可是我想写入的文本显示不出来
2. 如何实现在RichTextBox的中的文本末尾插入该表情,且能够用BackSpace键实现删除该表情,就像删除文本一样?
3. 插入多个表情时如何实现?Imports System.Windows.Forms
Imports System.Drawing
Public Class ExRichTextBox
Inherits RichTextBox 'Create a Bitmpap Object.
Private animatedImage As New Bitmap("shy.gif")
'Private animatedImage As Image
Private currentlyAnimating As Boolean = False
Public Sub New() Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.UserPaint, True)
AnimateImage()
End Sub
'This method begins the animation.
Public Sub AnimateImage() If Not currentlyAnimating Then 'Begin the animation only once.
ImageAnimator.Animate(animatedImage, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = True
End If
End Sub Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs) 'Force a call to the Paint event handler.
Me.Invalidate()
End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e) 'Get the next frame ready for rendering.
ImageAnimator.UpdateFrames(animatedImage) 'Draw the next frame in the animation.
e.Graphics.DrawImage(Me.animatedImage, New Point(20, 0)) '下面文本显示不出来
e.Graphics.DrawString("您好", New Font("Arial", 12, FontStyle.Bold), Brushes.AliceBlue, 0, 0)
End Sub
end class
1. 可是我想写入的文本显示不出来
2. 如何实现在RichTextBox的中的文本末尾插入该表情,且能够用BackSpace键实现删除该表情,就像删除文本一样?
3. 插入多个表情时如何实现?Imports System.Windows.Forms
Imports System.Drawing
Public Class ExRichTextBox
Inherits RichTextBox 'Create a Bitmpap Object.
Private animatedImage As New Bitmap("shy.gif")
'Private animatedImage As Image
Private currentlyAnimating As Boolean = False
Public Sub New() Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.SetStyle(ControlStyles.UserPaint, True)
AnimateImage()
End Sub
'This method begins the animation.
Public Sub AnimateImage() If Not currentlyAnimating Then 'Begin the animation only once.
ImageAnimator.Animate(animatedImage, New EventHandler(AddressOf Me.OnFrameChanged))
currentlyAnimating = True
End If
End Sub Private Sub OnFrameChanged(ByVal o As Object, ByVal e As EventArgs) 'Force a call to the Paint event handler.
Me.Invalidate()
End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e) 'Get the next frame ready for rendering.
ImageAnimator.UpdateFrames(animatedImage) 'Draw the next frame in the animation.
e.Graphics.DrawImage(Me.animatedImage, New Point(20, 0)) '下面文本显示不出来
e.Graphics.DrawString("您好", New Font("Arial", 12, FontStyle.Bold), Brushes.AliceBlue, 0, 0)
End Sub
end class
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货