如何使按钮继承其他按钮事件 [英] How do I make buttons inherit other button event
问题描述
我正在尝试从一个按钮继承按钮
例如我有5个按钮,其中一个具有MouseHover事件和MouseLeave事件,它将使button1.BorderStyle = BorderStyle.Fixed3D。我想要所有按钮
我知道我可以为所有按钮执行此操作但这是多余的/重复的吗?
我只是想让他们继承
我尝试了什么:
我试过发件人,但我不确定怎么做因为我在C#中有点新东西
I'm trying to make a button inherit from one button
For example i have 5 buttons one of them has MouseHover Event and MouseLeave Event that will make button1.BorderStyle = BorderStyle.Fixed3D. I want that for all buttons
I know I can do it for all the buttons but that is redundant/repetitive right ?
I just want them to inherit
What I have tried:
I have tried the sender but I am not sure what to do because I am kinda new in C#
推荐答案
一个Button控件没有BorderStyle属性(你不能设置按钮的边框样式)。 />
您可以使用Visual Studio intellisense检查控件的成员(属性,方法等),例如在'myButton'中键入'dot'后会出现一个弹出的成员列表。
您可以使用(例如)'c#按钮搜索Google '。
这里是如何为所有(或部分)按钮使用相同的MouseHover事件处理程序:
A Button control does not have a BorderStyle property (you can't set a button's border style).
You can check a control's members (properties, methods, etc.) with Visual Studio intellisense, e.g. you get a pop-up list of members after you type the 'dot' in 'myButton.'
You can alo search Google with (for example) 'c# button'.
And here's how to use the same MouseHover eventhandler for all (or some of) your buttons:
private void AllButtons_MouseHover(object sender, System.EventArgs e)
{
((Button)sender).Text = "Button Text";
}
BTW。您可能希望使用MouseEnter事件而不是MouseHover事件,以下是如何将多个鼠标事件指向同一个处理程序:
BTW. You probably want to use the MouseEnter event instead of the MouseHover event, and here's how to point multiple mouse events to the same handler:
myButton1.MouseEnter += AllButtons_MouseHover;
myButton2.MouseEnter += AllButtons_MouseHover;
// etc.
>
这篇关于如何使按钮继承其他按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!