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
lukasz - 13 Sep 2004 09:51 GMT
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);
> I have been having problems using invalidate which forms when the mouse is
> triggering the screen repainting. It seems that if the invalidate function
[quoted text clipped - 85 lines]
>
> End Class
Alex Glass - 14 Sep 2004 06:33 GMT
thanks for the help 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
[quoted text clipped - 101 lines]
> >
> > End Class