p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 8th, 2009, 12:28 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 23rd, 2009, 05:48 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 7th, 2009, 10:41 PM
Friend of Wrox
Points: 1,449, Level: 15
Points: 1,449, Level: 15 Points: 1,449, Level: 15 Points: 1,449, Level: 15
Activity: 17%
Activity: 17% Activity: 17% Activity: 17%
 
Join Date: Sep 2005
Location: , , .
Posts: 420
Thanks: 0
Thanked 14 Times in 14 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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Graphics scruffyduck BOOK: Visual Basic 2005 Programmer's Reference 14 July 23rd, 2008 12:21 PM
c/c++ graphics hafizmuhammadmushtaq C++ Programming 0 October 20th, 2007 12:33 AM
Help on graphics steparths C++ Programming 0 June 30th, 2006 03: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



All times are GMT -4. The time now is 03:08 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc