O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Paint Dynamic Content

Problem

You want to draw a combination of elements on a form and track them so that they can be redrawn later.

Solution

Place all your drawing code in an event handler for the Form.Paint event. When you need to update the form, call the Form.Invalidate method.

Discussion

In many applications, drawing takes place in response to another action, such as a user clicking a button or clicking directly on the form surface. Consider the example shown in Figure 12-8, in which the user can draw a small square object anywhere on a form simply by clicking with the mouse.

Custom drawing.

Figure 12-8. Custom drawing.

In this case, you have two choices:

  • Use drawing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required