Wrox Programmer Forums
|
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2009, 11:28 AM
Registered User
 
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Painting and Graphics

Good Morning!

Maybe someone could help me out to understand Paint Events and drawing Graphics.

I have a main form with with an array of usercontrols on it; these Usercontrols are used so that graphics are drawn on each one independent of one another.

In the Main Form Load Event, I call a DrawMain subroutine which loops through each UserControl to perform graphic drawings. As the program loops through each UserControl, I call a subroutine called RefreshScreen which in turn calls the UserControl_Refresh method. This forces a UserControl_Paint event, which then draws my graphics accordingly. This occurs for each userControl until the loop is finished and proceeds.

I also use the Form_Paint Event where i call the DrawMain subroutine to update the screen display. After this initialization, I use a timer to refresh the screen display every 5 seconds.

I noticed that my Form_Paint event fires infinitely and never enters the TimerRefresh_Tick event that i use to refresh the screen. How come this would fire infinitely? What is the proper method for using the Paint Method to update graphics?

My thinking is this with the Order of Events:

Form_Load >>>> Calls Private Sub DrawMain
DrawMain >>>>> Calls UserControl Public Sub RefreshScreen
RefreshScreen >>>>>> Calls UserControl.Refresh Method
UserControl.Refresh >>>>> Forces UserControl_Paint Event
UserControl_Paint >>>>> Draws Graphics
Drawn Graphics >>>>> Forces Form_Paint Event to Trigger
Form_Paint >>>>> Calls Private Sub DrawMain

Thank you in advance for any thoughts on this topic!

Thanks,

Tuzz
 
Old October 23rd, 2009, 04:48 PM
Registered User
 
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Discovered an answer, possibly!

After much heartache and toil, i discovered the following conclusion in regards to painting graphics in the paint event:

When painting graphics using the Paint Event for a control, a user must not modify any properties of that control that may trigger a paint event (i.e ForeColor, BackColor, etc....). Doing so will or may cause an infinite paint loop that never ceases. So, in other words, the Paint Event can only be used solely for graphics manipulation, control properties may not be modified while in the paint event.

I may be wrong on this, but as soon as i discovered this, I was able to get my program to work the way i wanted it.

Hope this sheds some light for other users, maybe this can help!
 
Old November 7th, 2009, 10:41 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

You can try disabling the events before changing forecolor, backcolor etc

and then enable the event handler after the job is done

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
c/c++ graphics hafizmuhammadmushtaq C++ Programming 0 October 19th, 2007 11:33 PM
Help on graphics steparths C++ Programming 0 June 30th, 2006 02:09 PM
graphics in C++ MASTER_1st C++ Programming 2 November 28th, 2005 12:02 AM
Exception while painting properties window... KRYSTAAL BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 December 12th, 2003 10:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.