User Controls
This section of the website concentrates on User-Controls. It provides basic instructions and code
for adding new controls to a VB.Net project. There are instructuctions at the end of this page
to overcome a specific compiler error which may occur when using certain versions of VB.Net
How To Add This Sites User Controls to Your Project
These instructions are based on a VB.Net 2026 version. There may be slight differences when using other VB.Net versions.- Open your project for editing as normal
- Click on "Project" (on main menu at top of page)
- Click on "Add User Control (Windows Forms)
- Click on "User Control (Windows Forms)
- Get the name of UserControl (as indicated on web page) and type it into "Name" text box
- Click the "Add" button at the bottom of the page
- Wait for the user control's (Design) screen to be added to the project
- Do not change anything on the (Design Screen) you will copy/paste code which includes any design elements later
- Double Click the control outline on the design screen and wait fior the Controls .VB code screen to appear
- Copy and Paste the used control code into the .VB code screen. (It should replace any code that already exists)
- Fix any error messages relating to your project
- Attempt to run your project (this builds the control and makes it available to your main project.)
- Stop your program - the new user control will now be available (alongside labels, textboxes, etc. in your project's toolbox.
Compilation Problem - The Public Property... lines
Information is normally passed between programs and user controls using a special type of "parameter" known as a property.
Older versions of VB.Net defined a property using similar code to this
Public Property MyProperty As Integer
Get
Return _MyProperty1
End Get
Set(value As Integer)
_MyProperty1 = value
End Set
End Property
Some versions of VB.Net will not accept this code and you could encounter errors pointing to the line
Public Property MyProperty As Integer
If you experience this problem, try adding the compiler instruction
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Insert the line immediately before the Public Property ... line and ensure the line starts with < and ends with >(Avoid placing any comments, blank lines or other code between <Designer.... and Public Property)
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Property MyProperty As Integer
Get
Return _MyProperty1
End Get
Set(value As Integer)
_MyProperty1 = value
End Set
End Property
It is possible that an older version of VB.Net could complain about the <Designer... instruction - if this happens,
try commenting out the <Designer... line
' <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Property MyProperty As Integer
Get
Return _MyProperty1
End Get
Set(value As Integer)
_MyProperty1 = value
End Set
End Property
The line
Imports System.ComponentModel
is required by the
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
line. If your version of VB.Net does not require
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
you may also have to comment out the
Imports System.ComponentModel
DigitalDan.co.uk