The PlotControl

Team Fly 

Page 590

The second application is a fractal generator. Fractals are a special type of function plotting; instead of a simple curve, fractals fill the space with intricate patterns of startling beauty. The fractal generator is not a practical application in a strict sense, but it's a fun application you can use to experiment with fractals.

The PlotControl

Our first sample application is a custom control for plotting two-dimensional functions, as shown in Figure 20.1. Figure 20.1 shows a test form that uses the PlotControl. The control, which takes up the upper part of the form, displays the plot of the two functions specified in the TextBox controls near the bottom of the form. To create a plot, you set the control's properties and then call the Plot method.

Create a new solution in Visual Studio and add two projects to it: a Windows Control Library (the PlotControl project) and a Windows project (the TestProject). The Windows project is the test project for the control. The PlotControl is a compound custom control that contains a PictureBox control, where the function plots and the grid are drawn. The titles and the axis numbers are printed on the control itself. The PictureBox control is anchored at all four sides and the bands around it, where the elements of the plot are drawn, have fixed sizes. In our code we set up two Graphics objects for drawing. The G Graphics object represents the surface of the control. This is where we'll draw the axis titles and numbers, and the G object is created with the following statements:

 Dim bmp As Bitmap bmp = New Bitmap(Me.Width, Me.Height) Me.BackgroundImage = bmp Dim G As Graphics G = Graphics.FromImage(bmp) 

image

FIGURE 20.1 Using the PlotControl in a test application

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