本文整理汇总了C#中System.Windows.Forms.Button类的典型用法代码示例。如果您正苦于以下问题:C# Button类的具体用法?C# Button怎么用?C# Button使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Button类属于System.Windows.Forms命名空间,在下文中一共展示了Button类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeMyButton
private void InitializeMyButton()
{
// Create and initialize a Button.
Button button1 = new Button();
// Set the button to return a value of OK when clicked.
button1.DialogResult = DialogResult.OK;
// Add the button to the form.
Controls.Add(button1);
}
示例2: new Button()
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class FormHand : Form
{
private TextBox firstNameBox = new TextBox();
private Button btnShowControls = new Button();
public FormHand()
{
firstNameBox.Text = "Text";
firstNameBox.Size = new Size(150, 50);
firstNameBox.Location = new Point(10, 10);
this.Controls.Add(firstNameBox);
btnShowControls.Text = "Click Me";
btnShowControls.Size = new Size(90, 90);
btnShowControls.Location = new Point(10, 70);
btnShowControls.Click += new EventHandler(btnShowControls_Clicked);
this.Controls.Add(btnShowControls);
CenterToScreen();
}
protected void btnShowControls_Clicked(object sender, EventArgs e)
{
Control.ControlCollection coll = this.Controls;
foreach(Control c in coll)
{
if(c != null)
Console.WriteLine(string.Format("Index: {0}, Text: {1}\n", coll.GetChildIndex(c, false), c.Text));
}
MessageBox.Show("Message", "Index and Text values for each control");
}
public static int Main(string[] args)
{
Application.Run(new FormHand());
return 0;
}
}