Flickering Problem in Text Control
Visual Basic
1
Posts
1
Posters
0
Views
1
Watching
-
As part of a presentation software, I decided to write a custom control that provides cool text effects (like in powerpoint 2007). To support transparency, I used Bob Powell's code. Everything is fine in the designer, but when I try to animate the control, it flickers a lot. Double buffering just gives it a black background. Can anyone help me remove the flicker? The code for the class:
Imports System.Drawing.Drawing2D
Public Class Text2007
Inherits System.Windows.Forms.UserControlProtected Overrides ReadOnly Property CreateParams() As CreateParams Get Dim cp As CreateParams = MyBase.CreateParams cp.ExStyle = cp.ExStyle Or &H20 Return cp End Get End Property Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs) End Sub Protected Sub InvalidateEx() If (Parent Is Nothing) Then Exit Sub Else Dim rc As New Rectangle(Location, Size) Parent.Invalidate(rc, True) End If End Sub Protected Overrides Sub OnMove(ByVal e As EventArgs) Me.InvalidateEx() End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim bm As New Bitmap(CInt(Me.ClientSize.Width / 5), CInt(Me.ClientSize.Height / 5)) Dim pth As New GraphicsPath() pth.AddString(Me.Text, New FontFamily("Verdana"), CInt(FontStyle.Regular), 100, New Point(20, 20), StringFormat.GenericTypographic) Dim h As Graphics = Graphics.FromImage(bm) Dim mx As New Matrix(1.0F / 5, 0, 0, 1.0F / 5, -(1.0F / 5), -(1.0F / 5)) h.SmoothingMode = SmoothingMode.AntiAlias h.Transform = mx Dim p As New Pen(Color.Yellow, 3) h.DrawPath(p, pth) h.FillPath(Brushes.Yellow, pth) h.Dispose() e.Graphics.Transform = New Matrix(1, 0, 0, 1, 50, 50) e.Graphics.SmoothingMode = SmoothingMode.AntiAlias e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic e.Graphics.DrawImage(bm, ClientRectangle, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel) e.Graphics.FillPath(Brushes.Black, pth) pth.Dispose() End Sub Public Sub pInvalidate() Me.InvalidateEx() End Sub
End Class
~ Soumya92