BUTTON控件

button控件属性表:

PropertyDescription
AutoEllipsis Specifies whether to append dots () when the text in the button is too long and can't fit the button.
AutoSize Specifies whether the button will automatically resize to fit its content.
FlatStyle Determines the style of the button. Popup makes the button flat, and when you hover on the button, the button will pop out. Flat makes the button flat and when you move point your mouse inside the button, the background color of the button changes.
Enabled If set to false, the button cannot be clicked or receive focus.
Image An optional image that you can place inside the control.
ImageAlign The alignment of the image in the button.
Text The caption inside the button.
Visible Tells whether the button is visible or not.

事件列表:

EventDescription
Click Occurs when you click the button.
Enter Occurs when the control becomes the
active control of the form.
Leave Occurs when the control becomes
inactive anymore.
LocationChanged Occurs when the location of the
button is changed.
MouseDown Occurs when the mouse pointer is in the button
and the mouse button is pressed down.
MouseEnter Occurs when the mouse enters the button.
MouseHover Occurs when the mouse stays stationary
in the button for an amount of time.
MouseUp Occurs when you pressed the button and
you let go of the mouse button.
MouseLeave Occurs when the mouse pointer
leaves the button.

Click作为button的默认事件。我们也可以为 button添加其它事件。建立一个新的窗体,从工具箱拖拽一个button控件到窗体上,把button的name属性设为buttonsample。接着为窗体添加MouseEnter 和 MouseLeave事件。

打开属性窗口,单击“闪电”标识添加事件,如下图:

Accessing events from the Properties Window

MouseEnter 事件代码:

private void buttonSample_MouseEnter(object sender, EventArgs e)
{
    buttonSample.Text = "Mouse has entered!";
}

MouseLeave事件代码:

private void buttonSample_MouseLeave(object sender, EventArgs e)
{
    btnSample.Text = "Mouse has left!";
}

运行结果截图如下:

Button Control Button Control

posted @ 2011-06-25 00:56  Irving314  阅读(1524)  评论(0编辑  收藏  举报