动态按钮的属性 [英] property of a dynamic button

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

问题描述

单击按钮时会更改哪个按钮属性?
动态按钮的属性也一样吗?

which button property is changed when a button is being clicked?
is that property same for the dynamic buttons also?
can any one give an example?

推荐答案

单击按钮时未更改按钮属性:您获得了一个事件(Button.Click事件),因此您可以当事情发生时就去做.

突出显示您的按钮,然后在VS的属性"窗格中查找.按下闪电"按钮以显示可用事件,然后双击单击"以添加处理程序.

动态按钮也会发生同样的事情,但是在创建动态按钮时,您必须手动添加处理程序. VS可以提供​​帮助:键入您的按钮创建代码,然后键入myButton.Click + =
No button property is changed when a button is clicked: you get an event (the Button.Click event) so that you can do your thing when it happens.

Highlight your button, and look in the Properties pane of VS. Press the "lightning flash" button to show the available events, then double click on "Click" to add a handler.

The same thing happens with dynamic buttons, but you have to add the handler manually when you create them. VS can help: type your button creation code then type myButton.Click +=
Button myButton = new Button();
myButton.Click +=

按两次[TAB],它将为您填充.


如果按钮是由动态按钮数组创建的,那么如何在数组中的其他动态按钮中识别单击的按钮?"


容易-将它作为发送者"参数传递给事件处理程序:

Press [TAB] twice and it will be filled in for you.


"if the buttons are created by a dynamic button array,how can we identify a clicked button,among the other dynamic buttons in an array?"


Easy - it is handed to the Event handler as the "sender" parameter:

private void myButton_Click(object sender, EventArgs e)
   {
   Button pressed = sender as Button;
   if (pressed != null)
      {
      // "pressed" is the button the user clicked
      }
   }

检查null的唯一原因是可以直接调用事件处理程序:不建议,但可以.如果发生这种情况(或将事件挂接到其他控件类型),则不会引发异常.

The only reason to check for null is that it is possible to call event handlers directly: not advisable, but possible. If this happens (or the event is hooked to a different control type) then it will not throw an exception.


无.时期.没有例子.阅读events的工作原理.

—SA
None. Period. No examples. Read on how events works.

—SA




当您单击按钮时,外观可以更改eventHandler函数中的按钮


when u click a button the Look and feel u can change Of Button in eventHandler function
private void button1_MouseHover(object sender, EventArgs e) {
    // when we hoover the button we get this
    button1.BackColor = Color.LightGreen;
}
private void button1_MouseLeave(object sender, EventArgs e) {
    // when we again leave the button we get back original color
    button1.BackColor = Color.Aqua;
}
private void Form1_Load(object sender, EventArgs e) {
    // Lets start with this color
    button1.BackColor = Color.Aqua;
}



[edit]伪造的行代码,很大,从答复结尾删除了代码块-OriginalGriff [/edit]



[edit]Spurious in line code, big, code block removed from end of reply - OriginalGriff[/edit]


这篇关于动态按钮的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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