Testing the Gauge Control
The code to test the Gauge control is very simple. The text boxes shown in Figure 22.9, from top to bottom, are txtMin , txtMax , txtDanger , txtCaution , and txtCurrent . The two buttons are btnTest and btnExit . The testing code is shown in Listing 22.7.
Listing 22.7 Code for Testing the Gauge Control
Public Class frmGaugeTest Inherits System.Windows.Forms.Form ' Windows Form Designer generated code Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnExit.Click Me.Dispose() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles MyBase.Load txtMax.Text = "3000" txtMin.Text = "0" txtDanger.Text = "2700" txtCaution.Text = "2400" txtCurrent.Text = "2600" End Sub Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnTest.Click Gauge1.Maximum = CDbl(txtMax.Text) Gauge1.Minimum = CDbl(txtMin.Text) Gauge1.Danger = CDbl(txtDanger.Text) Gauge1.Caution = CDbl(txtCaution.Text) Gauge1.Current = CDbl(txtCurrent.Text) Gauge1.Invalidate() End Sub End Class
When the form is loaded, you initialize some sample test values into the appropriate text boxes. When the user clicks the Test button, these values are passed to the Gauge control to set the member data values for the gauge. The call to the gauge's Invalidate() method causes the gauge to be redrawn using the new values. A sample run is shown in Figure 22.11.
Figure 22.11. A sample run of the program to test the Gauge control.
Although you cannot see it, the color in the sample run is yellow because the current test value falls between the Caution and Danger values.
You should type in different test values to see how the gauge responds. You might also try values that do not fall within the current range of the control to see if the control handles them properly. I also encourage you to use the Visual Basic .NET debugger to single-step through the code, looking at the values of the variables in the Locals window. That is a great way to gain a real understanding of how the code works.