简体   繁体   English

关闭另一个“表单”时如何将焦点集中到“标签页”

[英]how to `focus` to `tabpage` when close another `form`

I have two forms, form0 and form1 . 我有两种形式, form0form1 form0 has a tabcontrol with three pages. form0具有一个包含三个页面的tabcontrol。 ( tagpage1 , tabpage2 and tabpage3 ) tagpage1tabpage2tabpage3

I want tabpage2 to be focused when form1 closes. 我希望在form1关闭时对tabpage2进行聚焦。 So basically, how do I control the state of a tabpage of another form's tabcontrol? 因此,基本上,我如何控制另一个表单的tabcontrol的选项卡页的状态?

Any help is very much appreciated! 很感谢任何形式的帮助!

That's what event handlers are designed to do. 这就是事件处理程序的目的。 You'll want to write a handler for the form's FormClosed event. 您将要为表单的FormClosed事件编写一个处理程序。 Similar to this: 与此类似:

    private void button1_Click(object sender, EventArgs e) {
        var frm = new form1();
        frm.FormClosed += new FormClosedEventHandler(frm_FormClosed);
        frm.Show();
    }

    void frm_FormClosed(object sender, FormClosedEventArgs e) {
        tabControl1.SelectedTab = tabPage2;
    }

Or more compactly: 或更紧凑:

        var frm = new form1();
        frm.FormClosed += delegate { tabControl1.SelectedTab = tabPage2; };
        frm.Show();

With the Big Advantage that this is now entirely an implementation detail of form0, no special code or knowledge of form0 is required in the form1 class. 有了最大的优势,现在这完全是form0的实现细节,因此form1类中不需要特殊的代码或对form0的了解。

在关闭Form1时未在窗体中的名称空间级别中定义静态事件触发此事件并在Form2上进行处理以选择require选项卡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM