We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Change focus of the flap automatically when clicking

Good Morning,

I am not able to change the focus of the tab, created by MDI, when selecting the corresponding menu / option, I did not find or I was able to create an event for this.

In the system I have a menu, which each when clicking creates an MDI tab (which is created only once, avoiding duplicate tabs).

When I click on a menu, where the created tab already exists, I would like the focus to go directly to that tab.

Below I will replicate my code, and attached an image to better exemplify it.

        private void MenuEmpresasClick(object sender, EventArgs e)
        {
            this.IsMdiContainer = true;
            this.tabbedMDIManager1.AttachToMdiContainer(this);
            this.tabbedMDIManager1.TabStyle = typeof(Syncfusion.Windows.Forms.Tools.TabRendererDockingWhidbey);

            MetroForm2 form = new MetroForm2 { Text = "Empresas" };

            var childrenFind = this.tabbedMDIManager1.MdiChildren.Where(f => f.Text == form.Text).Any();

            if (!childrenFind)
                form.MdiParent = this;
            else
               // focus on the flap that is already open


        }

Thank you,

Júlio C. Mendonça

Attachment: Question_WinForms_180787b9.rar

3 Replies

JP Jagadeesan Pichaimuthu Syncfusion Team May 23, 2019 01:11 PM UTC

Hi Julio 
  
Thanks for your contacting Syncfusion support. 
  
We have checked your query “Need to change focus to the corresponding tab when click the menu item”. We have hosted the child of TabbedMDIManager inside the TabControlAdv.  We can achieve your requirement using TabControlAdv with help of the TabControlAdded event of TabbedMdIManager. We have prepared the sample, In which we have set the selected tab(Tab which created already) when you click the menu item. Please find the code Snippet and Sample for the same. 
  
Code Snippet: 
  
  this.tabbedMDIManager1.TabControlAdded += TabbedMDIManager1_TabControlAdded; 
            Form2 form = new Form2 { Text = "Titulos" }; 
            form.BackColor = Color.Red; 
            form.MdiParent = this; 
            form.Show(); 
            this.mainFrameBarManager1.Style = VisualStyle.Office2016Colorful; 
            this.barItem1.Click += ParentBarItem1_Click; 
        } 
  
        private void TabbedMDIManager1_TabControlAdded(object sender, TabbedMDITabControlEventArgs args) 
        { 
            tabcontrol = args.TabControl; 
        } 
  
        private void ParentBarItem1_Click(object sender, System.EventArgs e) 
        { 
            MetroForm form = new MetroForm { Text = "Empresas" }; 
  
            var childrenFind = this.tabbedMDIManager1.MdiChildren.Where(f => f.Text == form.Text).Any(); 
  
            if (!childrenFind) 
            { 
                form.MdiParent = this; 
                form.Show(); 
            } 
            else 
            { 
                if(tabcontrol != null) 
                { 
                    foreach(TabPageAdv page in tabcontrol.TabPages) 
                    { 
                        if(page.Text== form.Text) 
                        { 
                            // focus on the flap that is already open 
                            tabcontrol.SelectedTab = page; 
                            break; 
                        } 
                    } 
                 
                } 
               
            } 
  
        } 
    } 
} 
  
  
Please try this above solution and let us know if it is helpful. If we misunderstood your requirement, please provide more information regarding the requirement. It would be more helpful to proceed further. 
  
Regards, 
Jagadeesan


JC Julio Cezar Mendonca May 23, 2019 04:00 PM UTC

Good afternoon

Got it. Thanks for the help and clarification.

Júlio C. Mendonça


JP Jagadeesan Pichaimuthu Syncfusion Team May 24, 2019 06:44 AM UTC

Hi Julio, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Jagadeesan 


Loader.
Live Chat Icon For mobile
Up arrow icon