Show UserControl as form

false74

Well-known member
Joined
Aug 4, 2010
Messages
76
Programming Experience
Beginner
I have a class that inherits the UserControl class, the class creates its own graphics such as a title bar and what not. Is it possible to show this class as a form/it's own window?

VB.NET:
Public Class CustomForm
    Inherits System.Windows.Forms.UserControl
    'create new instance, assign/declare vars here, blah blah
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
      'graphics drawn here
    End Sub
End Class

then be able to show this object as a window:

VB.NET:
Dim form as new CustomForm
form.show()
 
A UserControl is just a control, so you can put it on a form like any other control. If you can display a form with a Button on it then you can display a form with your UserControl on it.
 
Forms inherits the Form class (or derived), which has basically the same designer surface as a UserControl, so you could easily make that class a Form type class if you wanted that.
If you want to keep it as a control you must add an instance to a form and show that like jmcilhinney said.
 
Back
Top