473,473 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Different form classes as parameters for one sub

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
3 1027
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
* "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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: VM | last post by:
I have a Windows form that may be called with two parameters or three parameters (depending on who's invoking the form). The form was programmed so it received three parameters. How can I create an...
11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
3
by: J-T | last post by:
Hello, I am trying to create a web service which has 3 parameters. 1) Datasource 2)USerName 3)Password based on datasource and in the run time ,I have to switch between data identity...
10
by: Arno R | last post by:
Hi all, I have a database that I need to use in different versions of Access. This is A97 in most places and A2k in a few other locations. (I develop in A97 and convert the db to A2k for these...
9
by: PCI | last post by:
A Thread is created on form1 that addresses a sub in another class. When attempting to invoke and sub on the main form I recieve an error about a Window Handler needing to be created first. Is...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
2
by: pat.saunders | last post by:
Hi, I am using Visual Studio 2005 and am using Visual C#. I notice that the program.cs creates an instance of a form and runs it. I have a PictureBox in the form and a Class File x.cs and in the...
4
by: Ed Bitzer | last post by:
Appreciate some direction as to what most of you professionals do when passing some limited variables to another form. A simple example would be passing the location of a second form. I could use...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.