Hi PRA,
Check this example. Now please take its reference and correct your code.
I have three Forms Form1, MainForm and User form.
In Form1 Button click i am opening other two form.
C#
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
}
public DataTable GetNameForms()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("NameForm");
dt.Rows.Add(1, "User");
dt.Rows.Add(2, "MainForm");
return dt;
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = GetNameForms();
foreach (DataRow dr in dt.Rows)
{
string formName = this.GetType().Namespace + "." + dr["NameForm"].ToString();
var form = (Form)Activator.CreateInstance(Type.GetType(formName));
form.StartPosition = FormStartPosition.CenterScreen;
form.Show();
}
}
}
VB.Net
Public Class Form1
Public Sub New()
InitializeComponent()
Me.StartPosition = FormStartPosition.CenterScreen
End Sub
Public Function GetNameForms() As DataTable
Dim dt As DataTable = New DataTable()
dt.Columns.Add("Id")
dt.Columns.Add("NameForm")
dt.Rows.Add(1, "User")
dt.Rows.Add(2, "MainForm")
Return dt
End Function
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
Dim dt As DataTable = GetNameForms()
For Each dr As DataRow In dt.Rows
Dim formName As String = Me.GetType().Namespace & "." & dr("NameForm").ToString()
Dim form = CType(Activator.CreateInstance(Type.GetType(formName)), Form)
form.StartPosition = FormStartPosition.CenterScreen
form.Show()
Next
End Sub
End Class
Screenshot