Wrapping a WinForm in a class

W

Wayne

I have a winform that runs on its own, is it possible to wrap a stand-alone
winform in a class?

More accurately, is it possible to use a class to call an already
established winform?
 
H

Herfried K. Wagner [MVP]

Wayne said:
I have a winform that runs on its own, is it possible to wrap a
stand-alone winform in a class?

Windows Forms forms are already classes.
More accurately, is it possible to use a class to call an already
established winform?

You will have to make a reference to your instance of the Windows Forms form
available to the class. If you are instantiating your class from within
your form, you can add a property of the form's type to the class and set
this property to 'Me'. If there is only max. one instance of the form, you
can implement the singleton design pattern in order to easily access the
form's instance.
 
K

Ken Tucker [MVP]

Hi,

In addition to Herfeid's comments. You could try something like
this.

Public Class Form2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "


Private Shared instance As Form2

Public Shared ReadOnly Property DefInstance() As Form2
Get
If instance Is Nothing Then instance = New Form2
Return instance
End Get
End Property
End Class

To use

Dim frm As Form2 = Form2.DefInstance
frm.ShowDialog()

Ken
------------------
I have a winform that runs on its own, is it possible to wrap a stand-alone
winform in a class?

More accurately, is it possible to use a class to call an already
established winform?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top