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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification