如何通过单击第一个表单上的按钮来禁用第二个表单上的按钮 [英] How do I disable the button on second form by clicking the button on first form

查看:51
本文介绍了如何通过单击第一个表单上的按钮来禁用第二个表单上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过单击第一个表单上的按钮来禁用第二个表单上的按钮是否可以这样做?我是新手上的c#感谢您理解我,对不起,如果我没有得到您的解释,我需要输入什么代码或我应该在我的代码上执行此操作。



我尝试了什么:



仍然没有做任何事情,因为我不知道该放什么新手

I want to disable the button on second form by clicking the button on first form is it possible to do that? Im newbie on c# thank you for understanding me and Sorry if I didn't get your explanation and what code do I need to put or something I should put on my codes to perform that.

What I have tried:

Still didn't do anything because I dont know what to put Im Newbie

推荐答案

这是可能的,但您必须将按钮属性的范围更改为 Public ,例如在窗体设计器中。然后你可以这样做:
It's possible, but you will have to change the scope of the button property to Public, e.g. in the Forms Designer. Then you can do this:
Form2.Button1.Enabled = False;

当然还有其他更复杂的方法......



好​​的,我会详细说明一下:

Of course there are also other more complicated ways ...

Ok, I will elaborate a bit more:

private void button1_Click(object sender, EventArgs e)
{
    var form2 = new Form2();

    // The 'Modifiers' property of button2 has been set to Public in the Forms designer.
    form2.button2.Enabled = false;
    form2.Show();
}



或者如果您需要在使用Form2时更改按钮:


Or if you need to change the button while Form2 is in use:

public partial class Form1 : Form
{
    Form2 form2 = new Form2();

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        form2.Show();
    }

    private void buttonDisable_Click(object sender, EventArgs e)
    {
        // The 'Modifiers' property of button2 has been set to Public in the Forms designer.
        form2.button2.Enabled = false;
    }
}


这篇关于如何通过单击第一个表单上的按钮来禁用第二个表单上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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