To get a flavor of what you need to do to create a complete custom component, try this experiment:
- Open a new WindowsApplication project in VB.NET.
- Add a Check Box from the Toolbox to the form. (We're going to use it later anyway.)
- Open the code window and click on the plus sign to the left of the
#Region " Windows Form Designer
generated code "
to display it. Notice that all the code below has been added automatically in the right locations to support the Check Box.
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Me.CheckBox1 = New System.Windows.Forms.CheckBox()
Me.SuspendLayout()
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(56, 64)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(168, 56)
Me.CheckBox1.TabIndex = 0
Me.CheckBox1.Text = "CheckBox1"
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CheckBox1})
Me.ResumeLayout(False)
This, and more, is what you have to do to use a complete custom control. Keep in mind that all the methods and properties of the Check Box are in a class supplied by the .NET Foundation for your project.
But suppose you just want to add a little customization? Like, for instance, a checkbox that changed color instead of displaying the little "check" graphic when you use it as in the illustration above. We're going to build a class that does just this much and show you how to add it to your project in code. While this might be useful by itself, the real goal is to explain VB.NET's new "inheritance" capability to simply change the behavior of the existing Check Box control.
Next page >
Get Started Coding! >
Page 1,
2,
3