Wrox Programmer Forums
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 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 October 23rd, 2013, 12:55 AM
Authorized User
Join Date: Aug 2013
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Question Lesson25TryItClassesDraw

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?

Last edited by Wendel; October 23rd, 2013 at 12:58 AM.. Reason: Forgot to add QUOTE for code
Old October 23rd, 2013, 09:20 AM
Rod Stephens's Avatar
Wrox Author
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

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.

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

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

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