Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Thursday, March 22, 2012 6:49 PM
hi,
I am using c# as a programming language to develop a window form MDI application. I am using the menu control for navigation . I want that when i click on any menu control for navigation the new child form which open in the MDI section will open in tabbed format similar to the visual studio and if the form is already open then the tabbed page containing that form will be focused and no duplicate form will be seen?
please help asap.
Thank you
Monday, March 26, 2012 7:26 AM ✅Answered | 1 vote
This task requires additional programming or usage of a library.
code: http://www.codeproject.com/Articles/17640/Tabbed-MDI-Child-Forms
library: http://www.infragistics.com/dotnet/netadvantage/winforms/wintabbedmdi.aspx#Overview
Resolving n Evolving in C# (http://jeanpaulva.com)
Monday, April 2, 2012 7:30 AM ✅Answered | 1 vote
Hi Pujit,
You can iterate through the Form.MdiChildren array and check whether it contains current form. If it contains the form, then pass the reference and active this mdi child. Otherwise, create a new one. For example,
namespace TabbedMDIChildForms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_MdiChildActivate(object sender, EventArgs e)
{
if (this.ActiveMdiChild == null)
tabForms.Visible = false; // If no any child form, hide tabControl
else
{
this.ActiveMdiChild.WindowState = FormWindowState.Maximized; // Child form always maximized
// If child form is new and no has tabPage, create new tabPage
if (this.ActiveMdiChild.Tag == null)
{
// Add a tabPage to tabControl with child form caption
TabPage tp = new TabPage(this.ActiveMdiChild.Text);
tp.Tag = this.ActiveMdiChild;
tp.Parent = tabForms;
tabForms.SelectedTab = tp;
this.ActiveMdiChild.Tag = tp;
this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed);
}
else
{
tabForms.SelectedTab = this.ActiveMdiChild.Tag as TabPage;
}
if (!tabForms.Visible) tabForms.Visible = true;
}
}
// If child form closed, remove tabPage
private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
{
((sender as Form).Tag as TabPage).Dispose();
}
private void tabForms_SelectedIndexChanged(object sender, EventArgs e)
{
if ((tabForms.SelectedTab != null) && (tabForms.SelectedTab.Tag != null))
(tabForms.SelectedTab.Tag as Form).Select();
}
//private object SearchMDIChild(Type t)
//{
// object o = null;
// foreach (var v in this.MdiChildren)
// {
// //you can change the condition
// if (v.GetType() == t)
// {
// o = v;
// }
// }
// return o;
//}
private void newFormToolStripMenuItem_Click(object sender, EventArgs e)
{
newForm1 f1 = null;
foreach (var v in this.MdiChildren)
{
//you can change the condition
if (v.GetType() == typeof(newForm1))
{
f1 = v as newForm1;
this.ActivateMdiChild(f1);
break;
}
}
if (f1 == null)
{
f1 = new newForm1();
f1.MdiParent = this;
f1.Show();
}
}
private void newAnotherFormToolStripMenuItem_Click(object sender, EventArgs e)
{
// you need to add simliar code
newForm2 f2 = new newForm2();
f2.MdiParent = this;
f2.Show();
}
}
}
If you still have any doubt and concern about this issue, please let us know.
Best Regards,
Bob Wu [MSFT]
MSDN Community Support | Feedback to us
Wednesday, April 4, 2012 6:34 AM ✅Answered | 1 vote
Thanks Bob,
For your time and considerationGreeting of the Day,
I got the partial solution of my problem,By using above code the child forms are not opening again. please reconsiderd on full problem which is as below:
I want that suppose there are multiple diffrent forms are open in the MDI in tabbed format. Then if user click on the menu control item to open the form which is already open then the tab page containg that form should be focused instead of opening new from and creating new tab page.
In short "if user click on the navigation menu user must be on the desired tabpage without opining and creating new tab page".Ask for any clarification.
Thanks again for your valuable time.
Hi Pujit,
What do you mean by “if user click on the navigation menu user must be on the desired tabpage without opining and creating new tab page”?
I’m not sure if I understand you correctly, do you mean
If the form is already opened in a tab page, it will negative to that tab page.
If the form is not opened, it will create a new tab page and display the form in that tab page.
The code has already achieved this (the New Form item); you might try the entire code here.
If I misunderstood you, please kindly elaborate your question.
Best Regards,
Bob Wu [MSFT]
MSDN Community Support | Feedback to us
Saturday, March 31, 2012 7:06 AM
Hello paul,
Greeting of the day
Thanks a lot for your help, The code @ codeproject help me a lot to understand the problem but in this code a new tab page is added every time i click onthe navigation menu. I want if any page(Mdi children) is already open or added as a tab page inside the mdi form than this page than instead of adding it again as a tab pages the focus should go on the opened page in the mdi....(Same as visual studio ).?
Thanks a lot.
Tuesday, April 3, 2012 7:27 PM
Thanks Bob,
For your time and consideration
Greeting of the Day,
I got the partial solution of my problem,By using above code the child forms are not opening again. please reconsiderd on full problem which is as below:
I want that suppose there are multiple diffrent forms are open in the MDI in tabbed format. Then if user click on the menu control item to open the form which is already open then the tab page containg that form should be focused instead of opening new from and creating new tab page.
In short "if user click on the navigation menu user must be on the desired tabpage without opining and creating new tab page".
Ask for any clarification.
Thanks again for your valuable time.
Wednesday, April 4, 2012 7:20 PM
Thanks Bob I got the solution,
1. I have a another problem for you "I want to navigate yearwise and monthwise(both) in a datetimepicker. and how can i disabled certain date in the datetime picker.
- How can i use custom property of masked edit textbox(Suppose i want to set mask to take the charcter only(no sepcial char and numeric value allowed) in a masked edit textbox with or without space).Tell me about other possible cutomization also.
Thanks again for your valuable help.
Regards
Pujit
Thursday, April 5, 2012 1:33 AM
Hi Pujit,
As you have two different new questions, would you mind to create two threads in this forum?
Thank you for your understanding.
Best Regards,
Bob Wu [MSFT]
MSDN Community Support | Feedback to us