當前位置: 首頁>>代碼示例>>C#>>正文


C# Button類代碼示例

本文整理匯總了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);
 }
開發者ID:.NET開發者,項目名稱:System.Windows.Forms,代碼行數:11,代碼來源:Button

示例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;
    }
}
開發者ID:C#程序員,項目名稱:System.Windows.Forms,代碼行數:43,代碼來源:Button


注:本文中的System.Windows.Forms.Button類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。