Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

blinking issue while using invalidate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex Glass - 13 Sep 2004 05:27 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.