Closed alezhen closed 4 years ago
Hey alezhen,
Sorry for taking long to get you a solution to this. I took it upon myself to provide a sample app in c# which you can actually clone or if you just want a quick answer check out the wiki here https://github.com/JacksiroKe/MdiTabCtrl/wiki/Using-the-Control
Your method of switching to the desired tab is very inconvenient. You have to constantly keep in mind that the index matches the desired form. And when you switch to the tab, sort through the indexes in the search for the desired one. It would be much more convenient to use something like this: tabControl1.TabPages.Select(form_name);
Actually you don't need to know the indexes to get to select the tab that you need to make active. I just showed the underlying functions to do that because if you look at the attached screenshot you will see that there is a menu to show all the open tabs in your app. It's where the selection is done once you click on the menu. I guess I will just keep documenting this control better and better.
Your suggestion of tabControl1.TabPages.Select(form_name);
won't help here as much as it looks good because the form being added to a tab is an instance of the form you have decided to use there. It could be browser window or anything. Only an index of the tab could help you delete it or reposition it or even select it. So just check out my sample and see the menu feature that is located on the far right corner to sort you with that.
You don't understand my task. I need to activate the tab not manually, but programmatically. I have more than ten forms. Some of them are opened for the entire period of working with the program. And some open and close several times. My task when opening the form is to check: if the form is already open, then make it active.
Sorry for misunderstanding you. Am sorry that is a tall order I may not be able to give you a precise solution for that
About tab indexes: your index is shifting, and for a new tab, the index will always be 0.
I implemented my task like this:
Form cform = new NameMyForm(); OpenForm(cform);
private string ExplodeFormName(string source) { var temp1 = source.Split(new string[] { "," }, StringSplitOptions.None); var temp2 = temp1[0].Split(new string[] { "NameSpaceForm." }, StringSplitOptions.None); return temp2[1].Trim(); }
private void OpenForm(Form source) { int CountTab = tabControl1.TabPages.Count; for (int i = 0; i < CountTab;) { string FormName = ExplodeFormName(tabControl1.TabPages[i].Form.ToString()); if (FormName == source.Name) { tabControl1.TabPages[i].Select(); return; } i++; } tabControl1.TabPages.Add(source); }
Maybe someone will need it.
I can't figure out how to make the tab active if it is already open. I will be very grateful for the hint. I use the c# Windows Forms, Nuget package.
To open the desired tab, I use the following code: Form cform; cform = new Profile(); if (Application.OpenForms.OfType().Any())
{
return;
}
tabControl1.TabPages.Add(cform);
I need to go to the tab with this form if the form is already open.