更改接受标签按钮 [英] Change accept button with tabs

查看:161
本文介绍了更改接受标签按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#编写Windows窗体应用程序,它有三个标签,我想与有源标签接受按钮变化。就像当我在标签1我想按钮_1要接受按钮,但是当我在标签3我想button_3是我接受按钮。我无法弄清楚如何做到这一点,也许我不会在我的搜索使用正确的术语,但我不能在网上找到任何好的资源,向我展示如何做到这一点。

I have a windows form application written in C# and it has three tabs and I would like the accept button change with the active tab. Like When I am in tab 1 I want button _1 to be the accept button but when I am in tab 3 I want button_3 to be my accept button. I cannot figure out how to do this and maybe I'm not using the correct terms in my searches but I cannot find any good resources online showing me how to do this.

推荐答案

最好的猜测是在勾到<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.selectedindexchanged.aspx\"相对=nofollow> 的SelectedIndexChanged 选项卡控件的事件,改变的 的AcceptButton 取决于所选择的标签。伪code:

Best guess would be to hook in to the SelectedIndexChanged event on the tab control and change the AcceptButton depending on which tab is selected. Pseudo-code:

Form_OnLoad(...)
{
    this.tabControl.SelectedIndexChanged += (s,e) => {
        TabControl tab = s as TabControl;
        switch (tab.SelectedIndex){
            case 3:
                this.AcceptButton = this.button_3;
                break;
            case 2:
                this.AcceptButton = this.button_2;
                break;
            case 1:
            default:
                this.AcceptButton = this.button_1;
                break;
        }
    };
}

或者是诸如此类的东西。

Or something of the sort.

这篇关于更改接受标签按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆