简体   繁体   English

以不同形式引用的C#对象

[英]C# Object referenced in different forms

I created a button with a Mouse Click event. 我创建了一个带有Mouse Click事件的按钮。 I want this button with it's appearance and it's event code the same on all forms. 我希望此按钮具有外观,并且事件代码在所有表单上均相同。

Is there anyway to have a library type item you can define once and then reference it on other forms. 无论如何,有一个库类型项可以定义一次,然后在其他表单上引用它。 Right now when I make a change I have to update the button on all forms. 现在,当我进行更改时,我必须更新所有表单上的按钮。

Notes: When I show a form, I hide() the previous form so the forms this button appears on are never open together. 注意:显示表单时,我会隐藏()前一个表单,因此此按钮所显示的表单永远不会一起打开。

All you have to do is inherit from a Button class and then use your custom button class instead of Button . 您要做的就是从Button类继承,然后使用自定义按钮类代替Button

public class CustomButton : Button
{
    public CustomButton() : base()
    {
        // Set custom properties, event hooks, etc. here
    }
}

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

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