Chapter 20 Advanced Graphics

Team Fly 

Page 589

Chapter 20
Advanced Graphics

ONE OF THE MOST interesting aspects of a programming language is graphics. The graphics engine of .NET is the Graphics Device Interface (GDI+). GDI+ is part of the Windows XP operating system that provides support for two-dimensional vector graphics, imaging, and typography. GDI+ is the successor to the Windows Graphics Device Interface (GDI), but it's more than an improved version of GDI; it's a new optimized graphics engine with many new features. We looked at GDI+ in Chapter 7, where we discussed the new printing techniques of .NET. In Chapter 7 we focused on a few methods we use to generate business graphics: how to print text, how to create reports with tabular data, how to draw lines and frames. In this chapter, we'll explore methods for manipulating individual pixels on a bitmap.

To demonstrate the advanced graphics methods of this chapter, we'll build two very different applications, one for plotting functions and one for generating fractals. The first application is a custom control that will plot any user-supplied two-dimensional function. In the process you'll also learn how to evaluate math expressions at runtime. The PlotControl custom control, which you'll build in the following section, allows you to set the properties of the plot (the range of values over which the function will be plotted, the axis titles, the style and color of the plot, and more) and you can incorporate it into your applications to give them plotting capabilities.

PERSISTENT DRAWING

According to the documentation, you should insert your graphics statements into the OnPaint event, which is fired every time a form (or control) must be redrawn by Windows. In effect, this technique redraws your graphics elements every time a segment of the window is uncovered, or when the window is resized. The graphics you generate from within the OnPaint event are not persistent: they're redrawn on the form or control as needed.

A complicated drawing, such as the drawings we'll develop in this chapter, may involve a large number of calculations. If you create your graphics from within the OnPaint event handler, the calculations will be repeated every time the form is refreshed. As a result, the refresh operation won t be instant. To avoid this unnecessary delay, you can create persistent graphics by drawing on a bitmap object and then displaying this bitmap. The bitmap need not be refreshed and the form that contains it is redrawn instantly. In the examples of this chapter we'll create persistent graphics by drawing on a bitmap, which is the background image of a Form, or PictureBox control.

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net