I have third party control called TopicBar which looks like window xp navigation bar that you can see on the left side of a window
In my application I've 71 forms I have created a DB table to store all my forms Name
and Text
,A partcular user can add which forms(by searching form's name that I have already stored in a table) should add in topicbar as item.
For example, A form called FrmBill and its name is Bill once a user addes Bill to Topicbar it will successfully creates an item with name Bill,Now what I'm facing is I need to open the form FrmBill when that user clicks on Bill item in topicbar
I can get form name ie FrmBill is a user clicks in Bill but I couldnt open the form becuase I need to dynamically create instance or call Form here frmBill
what I have done so far
Dim formName As String
Dim frm As Form
Using conn As New SqlConnection(conn_str)
conn.Open()
Dim cmd As SqlCommand
cmd = New SqlCommand("", conn)
cmd.CommandText = "select top 1 formname from winforms where id=" & winformid & ""
formName = cmd.ExecuteScalar
'output: FrmBill
frm = New Form
frm.Name = formName '(FrmBill)
With frm
.MdiParent = FrmMain
.Show()
.Focus()
End With
End Using
Note: in this function I can get form name ie FrmBill
from the DB, but its not showing the actual form FrmBill
So is there anyways to declare form name like below
dim frm as new "& formname &"
It's not so easy as "dim frm as new "& formname &"", but it can be done doing something like this:
I mean, you have to store the Type of the class form.
Edit:
You can open a form so:
ok? Well. You can open a Form so:
Here, frmBill its the Type of the class. You have no frmBill explicit reference, so you have to load it dinamically.
How can be do? Using a "NET mechanism" called Reflection. You can create a class dinamically, specifing the class Type.
What is Plutonix saying? Suppose you have a public "Print" method in frmBill.
With my answer, you can't do this:
Because you only can access to System.Windows.Forms.Form methods (close, show, showdialog...)
You can improve this, using a custom base class, or using Interfaces, or base abstract class... as you need. You can combine different ideas, depending on what you need. For example, you can combine an Interface with a Superclass:
....
...
Now, you could do things like:
I don't know if this is wthat you're looking for, but I hope this can help you to learn more about NET possibilities.