Button myButton = new Button(); myButton.Text = "Click me"; myButton.Click += MyButton_Click; private void MyButton_Click(object sender, EventArgs e) { Console.WriteLine("Button clicked!"); }
Button myButton = new Button(); myButton.Text = "Submit"; myButton.BackColor = Color.Green; myButton.ForeColor = Color.White; myButton.Font = new Font("Arial", 12); //add button to form controls this.Controls.Add(myButton);
Button myButton = new Button(); myButton.Text = "Click me"; myButton.Location = new Point(50, 50); myButton.Size = new Size(100, 30); //add button to form controls this.Controls.Add(myButton);The Button component is part of the .NET Framework's System.Windows.Forms library.