
Creating Custom Controls in VBNet (not User Control, AFAIK)
Thanks, fellows, for the help. I managed to create a Custom
Control with the code below. However, I can not get it to appear
on the Toolbox.
The steps are listed after the code. Have I found a bug
or am I doing something wrong?
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Imports System.ComponentModel
Imports System.WinForms.Button
Public Class Btn2
Inherits System.WinForms.Button
Public Sub New()
MyBase.New
InitializeComponent
Me.BackColor = System.Drawing.Color.LightGray
End Sub
#Region " Component Designer generated code "
'Required by the Component Designer
Private components As Container
Private WithEvents Button1 As System.WinForms.Button
'NOTE: The following procedure is required by the Component
Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Button1 = New System.WinForms.Button
Button1.Location = New System.Drawing.Point(419, 124)
Button1.Size = New System.Drawing.Size(75, 23)
Button1.TabIndex = 0
Button1.Text = "Button1"
End Sub
#End Region
End Class
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Steps:
1) Select File | New | Project | Select Class Library | Set Name
to Btn1 | Press Enter
2) The Class Designer (CD) opens with the default name of
Class1.vb and the message:
"Drag components from the Server Explorer or Toolbox to the
designer surface".
3) Open Toolbox and drag a "Button" from the Win Forms Group to
the CD surface.
4) Double-click the CD surface to open the code window.
5) Added "Imports System.WinForm.Button" to the top.
Changed "Public Class 1" to "Public Class Btn1"
6) Changed "Inherits System.ComponentModel", right under the
Class Statement to "Inherits System.WinForms.Button".
7) Add under "InitializeComponent", "Me.BackColor =
System.Drawing.Color.LightGray"
8) Did a Build with no errors.
9) Checked Toolbox. Btn1 does not appear.
10) Went to Solutions Explorer (SE) and right-clicked References
| Add Reference | Browse and then selected the Btn1.dll and it
appeared under the References Heading.
11) Checked Toolbox again -- still no Btn1.
12) Set focus to the CD surface and pressed F7 to open the code
window.
13) Added "Imports Btn1" at the top of the code.
14) Did another Build -- with no errors.
15) Shift-F7 to return to the CD surfrace from the code window.
16) Checked ToolBox -- still no Btn1.
17) From top menu, select Project | Add Windows Form and then
Open. Form1 is added to the project.
18) Press F7 while focus is on the Forms Designer (FD) to open the
code window.
19) Added "Imports Btn1" to the top of the code.
20) Shift-F7 to return to the FD surface.
21) Checked Toolbox again. No Btn1.
22) WHAT DOES IT TAKE TO GET Btn1 ON THE TOOLBOX???
Posted: 11-28-2K 5:45a