Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Flickering Problem in Text Control

Flickering Problem in Text Control

Scheduled Pinned Locked Moved Visual Basic
graphicshelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Soumya92
    wrote on last edited by
    #1

    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.UserControl

    Protected 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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups