p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer (http://p2p.wrox.com/forumdisplay.php?f=574)
-   -   Lesson25TryItClassesDraw (http://p2p.wrox.com/showthread.php?t=91241)

Wendel October 23rd, 2013 12:55 AM

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.


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?

Rod Stephens October 23rd, 2013 09:20 AM

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.


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.

All times are GMT -4. The time now is 08:45 PM.

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