A
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
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