By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

Different form classes as parameters for one sub

P: n/a
Hi,

I have several forms in my application which are all inherited from
System.Windows.Forms.Form. Now I want to write one(!) function which gets
three parameters:

Sub OpenForm(frm as Class, userid As Integer, permission As Integer)
If CheckPermission(userid , permission) Then
Dim temp As frm = New frm
frm.ShowDialog()
Else
MsgBox("Access denied!!")
End if
End Sub

Call:
OpenForm(FormClass, 10, 20)

But I don't know how to pass the class into the sub. I tried Type, Control,
Class, Object and Form but nothing worked.

Thanks a lot.

volker jobst
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
small example you can use i think...

Public Class Start
Public Shared Sub main()
Dim s As New Start
s.DoIt()

' Application.Run(New Form1)
End Sub

Public Sub DoIt()
Dim showOne As Boolean = False
If (showOne) Then
ShowIt(GetType(FormOne))
Else
ShowIt(GetType(FormToe))
End If
End Sub

Public Sub ShowIt(ByVal formType As Type)
Dim newForm As Form = DirectCast(Activator.CreateInstance(formType),
Form)
newForm.ShowDialog()

End Sub
End Class
Public Class FormOne
Inherits Form

Public Sub New()
Me.BackColor = Color.Red
End Sub
End Class

Public Class FormToe
Inherits Form

Public Sub New()
Me.BackColor = Color.Plum
End Sub
End Class



"Volker Jobst" <bu****@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

I have several forms in my application which are all inherited from
System.Windows.Forms.Form. Now I want to write one(!) function which gets
three parameters:

Sub OpenForm(frm as Class, userid As Integer, permission As Integer)
If CheckPermission(userid , permission) Then
Dim temp As frm = New frm
frm.ShowDialog()
Else
MsgBox("Access denied!!")
End if
End Sub

Call:
OpenForm(FormClass, 10, 20)

But I don't know how to pass the class into the sub. I tried Type, Control, Class, Object and Form but nothing worked.

Thanks a lot.

volker jobst

Nov 20 '05 #2

P: n/a
* "Volker Jobst" <bu****@gmx.de> scripsit:
I have several forms in my application which are all inherited from
System.Windows.Forms.Form. Now I want to write one(!) function which gets
three parameters:

Sub OpenForm(frm as Class, userid As Integer, permission As Integer)


<URL:http://dotnet.mvps.org/dotnet/code/codingtechnique/>
-> "Instanzieren anhand des Klassennamens"

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3

P: n/a
Thank you Dominique, it looks like this is exactly what I've been looking
for.

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:u9*************@TK2MSFTNGP09.phx.gbl...
small example you can use i think...

Public Class Start
Public Shared Sub main()
Dim s As New Start
s.DoIt()

' Application.Run(New Form1)
End Sub

Public Sub DoIt()
Dim showOne As Boolean = False
If (showOne) Then
ShowIt(GetType(FormOne))
Else
ShowIt(GetType(FormToe))
End If
End Sub

Public Sub ShowIt(ByVal formType As Type)
Dim newForm As Form = DirectCast(Activator.CreateInstance(formType),
Form)
newForm.ShowDialog()

End Sub
End Class
Public Class FormOne
Inherits Form

Public Sub New()
Me.BackColor = Color.Red
End Sub
End Class

Public Class FormToe
Inherits Form

Public Sub New()
Me.BackColor = Color.Plum
End Sub
End Class



"Volker Jobst" <bu****@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

I have several forms in my application which are all inherited from
System.Windows.Forms.Form. Now I want to write one(!) function which gets three parameters:

Sub OpenForm(frm as Class, userid As Integer, permission As Integer)
If CheckPermission(userid , permission) Then
Dim temp As frm = New frm
frm.ShowDialog()
Else
MsgBox("Access denied!!")
End if
End Sub

Call:
OpenForm(FormClass, 10, 20)

But I don't know how to pass the class into the sub. I tried Type,

Control,
Class, Object and Form but nothing worked.

Thanks a lot.

volker jobst


Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.