Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 23rd, 2013, 01:55 AM
Authorized User
Points: 96, Level: 1
Points: 96, Level: 1 Points: 96, Level: 1 Points: 96, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2013
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Question Lesson25TryItClassesDraw

Hi
I am (or should I say was) unable to draw the rectangles/ellipses on Form1. After substituting my code with the code from the “downloads” I have narrowed the variation in my code down to:
additional code in Form1.Designer.cs.

Quote:
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_ Paint);
How do I get this code into my project? Hopefully, without having to do a lot of typing.

Can you elaborate on the “Form1_Paint” event handler. Do you type the code into Form1.cs or is there an easier solution (similar to double clicking on the Form for say the “Form1_Load” event handler?
Thanks
Wendel

Last edited by Wendel; October 23rd, 2013 at 01:58 AM. Reason: Forgot to add QUOTE for code
  #2 (permalink)  
Old October 23rd, 2013, 10:20 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,145, Level: 23
Points: 3,145, Level: 23 Points: 3,145, Level: 23 Points: 3,145, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 641
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi Wendel,

You can do either of the following (but not both). (I think the second approach is easier.)

1. Use this code to attach the Form1_ Paint method as an event handler to handle the Paint event.

Code:
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_ Paint);
You can place this code in the form's Load event handler. (Double click the form to open it.)

Now fill in the Paint event handler's code.

2. In the form designer, click on the form. Then in the Properties window, click the Events button (it looks like a lightning bolt) to see a list of the form's events.

In the Properties window, now that it is displaying the form's events, double-click on the Paint event handler. That will create an empty event handler where you can put your draw and fill statements.

This also attaches the event handler to the form so you don't need the "Paint +=" statement used by method 1.

I hope that helps.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off



All times are GMT -4. The time now is 11:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.