Johny Bravo
asked on
Switching between forms
Hi Experts,
I am developing a Windows application.
I have a MenuStrip which is having two menu as 'MultiSession' and 'Switch'.
Click on Multisession will create a new instance of the for.And Switch should be used for switching between forms.
(These are two different MDI forms)
I am setting variables in class file named 'BLTools '.
I am developing a Windows application.
I have a MenuStrip which is having two menu as 'MultiSession' and 'Switch'.
Click on Multisession will create a new instance of the for.And Switch should be used for switching between forms.
(These are two different MDI forms)
I am setting variables in class file named 'BLTools '.
private void multiSessionToolStripMenuItem_Click(object sender, EventArgs e)
{
if (BLTools.mdirunn == 1)
{
MessageBox.Show("You can have only two instances running at a time");
}
if (BLTools.mdicnt != 1)
{
MDIForm f2 = new MDIForm();
f2.Show();
BLTools.mdicnt = 1;
BLTools.mdirunn = 1;
}
}
//Switch menu
private void switchToolStripMenuItem_Click(object sender, EventArgs e)
{
//What code should be here
}
ASKER
"Make f2 as the member of your class "
By this what I get is,
I declared MDIForm f2 in class,and now
private void multiSessionToolStripMenuI tem_Click( object sender, EventArgs e)
{
if (BLTools.mdirunn == 1)
{
MessageBox.Show("You can have only two instances running at a time");
}
if (BLTools.mdicnt != 1)
{
BLTools.mdicnt = 1;
BLTools.mdirunn = 1;
f2 = new MDIForm();
f2.Show();
}
}
private void switchToolStripMenuItem_Cl ick(object sender, EventArgs e)
{
objMDI.Focus();
}
This is not working.I am sure I didn't get you right,pls explain.
By this what I get is,
I declared MDIForm f2 in class,and now
private void multiSessionToolStripMenuI
{
if (BLTools.mdirunn == 1)
{
MessageBox.Show("You can have only two instances running at a time");
}
if (BLTools.mdicnt != 1)
{
BLTools.mdicnt = 1;
BLTools.mdirunn = 1;
f2 = new MDIForm();
f2.Show();
}
}
private void switchToolStripMenuItem_Cl
{
objMDI.Focus();
}
This is not working.I am sure I didn't get you right,pls explain.
ASKER
this line objMDI.Focus();
is actually f2.Focus();
is actually f2.Focus();
ASKER
Ok
I have to make one poine here.
MDIForm.Show will create a New MDIForm.
First MDIForm is also running simultaneouly.
These are two different MDIForms.
I have to make one poine here.
MDIForm.Show will create a New MDIForm.
First MDIForm is also running simultaneouly.
These are two different MDIForms.
In your BLTools class, keep a reference to the next displayed form. When the user clicks "Switch," the class shows the next form and updates the reference to the previously visible form:
// In BLTools
protected static Form nextForm;
nextForm = first_instance_of_form;
// In Menustrip code
private void switchToolStripMenuItem_Click(object sender, EventArgs e)
{
BLTools.nextForm.Show();
BLTools.nextForm = this;
}
ASKER
Hi kaufmed,
thanks for your comment.
BLTools is in business layer so can't get form reference thee.
Further,on click on Switch on any of the two MDIForms,the other form should be visible.
Please help.
thanks for your comment.
BLTools is in business layer so can't get form reference thee.
Further,on click on Switch on any of the two MDIForms,the other form should be visible.
Please help.
ASKER
what do you mean by "first_instance_of_form"
should I set nextForm = new MDIForm();
I am just confused.Please guide me.
should I set nextForm = new MDIForm();
I am just confused.Please guide me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lott
NP :)
In the switchToolStripMenuItem_Cl
you can switch to f2 by calling the Focus method.
f2.Focus(); // To switch to f2.
Similarly call the Focus for the other form to switch to it.