blinking issue while using invalidate
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.

Post a new message to this list...

Alex Glass
I have been having problems using invalidate which forms when the mouse is
triggering the screen repainting. It seems that if the invalidate function
is called too frequently and unsightly blinking effect happens. Below is a
sample program which produces the effect I am trying to explain. Is there a
different way to cause the text to be repainted in response to the events
without causing the blinking?

Any suggestions or help would be greatly appreciated
-Alex Glass

' BLINK.VB
Public Class Blink

Inherits System.Windows.Forms.Form

Private mouse_pos_rect As Rectangle

Private form_size_rect As Rectangle

Private mouse_pos As String

Private form_size As String

Public Sub New()

MyBase.New()

ClientSize = New System.Drawing.Size(292, 260)

Name = "Blink"

Text = "Blink"

form_size_rect.X = 10

form_size_rect.Y = 10

form_size_rect.Height = 40

form_size_rect.Width = 300

mouse_pos_rect.X = 10

mouse_pos_rect.Y = 60

mouse_pos_rect.Height = 40

mouse_pos_rect.Width = 300

End Sub

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)

Dim g As Graphics = e.Graphics

Dim f As New Font("Arial", 30, FontStyle.Regular, GraphicsUnit.Pixel)

g.DrawString(mouse_pos, f, Brushes.Black, ToRectF(mouse_pos_rect))

g.DrawString(form_size, f, Brushes.Black, ToRectF(form_size_rect))

End Sub

Private Sub Blink_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize

form_size = "(" & ClientSize.Width & ", " & ClientSize.Height & ")"

Invalidate(form_size_rect)

End Sub

Private Sub Blink_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

mouse_pos = "(" & e.X & ", " & e.Y & ")"

Invalidate(mouse_pos_rect)

End Sub

Private Function ToRectF(ByVal rect As Rectangle) As RectangleF

Return New RectangleF(rect.X, rect.Y, rect.Width, rect.Height)

End Function

End Class

Reply to this message...
 
    
lukasz
Blinking occurs when you can perceive consecutive steps of drawing. In your
case the form's surface is always cleared before entering OnPaint, which
causes the nasty effect. You can improve this by enabling double-buffering,
either manual or automatic. If you want automatic, add this code in the
constructor:

this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer |
ControlStyles.Opaque |
ControlStyles.UserPaint,
true);

U¿ytkownik "Alex Glass" <Click here to reveal e-mail address> napisa³ w wiadomo¶ci
news:Wk91d.117781$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Alex Glass
thanks for the help lukasz!

"lukasz" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
> Blinking occurs when you can perceive consecutive steps of drawing. In
your
[Original message clipped]

Reply to this message...
 
 
System.Drawing.Brushes
System.Drawing.FontStyle
System.Drawing.GraphicsUnit
System.Drawing.RectangleF
System.Drawing.Size
System.EventArgs
System.Windows.Forms.ControlStyles
System.Windows.Forms.Form
System.Windows.Forms.MouseEventArgs
System.Windows.Forms.PaintEventArgs




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com