using System;
using System.Drawing;
using System.Windows.Forms;
namespace Demo
{
public partial class Buttons : Form
{
//Define button array of length 4.
Button[] btnArray = new Button[4];
public Buttons()
{
InitializeComponent();
addButtons();
}
private void addButtons()
{
//Horizontal and vertical position of buttons
int xPosition = 0, yPosition = 50;
for(int i = 0; i < 4; i++)
{
btnArray[i] = new Button();
btnArray[i].Size = new Size(70, 23);
btnArray[i].Text = “Push Me”;
btnArray[i].Location = new Point(xPosition, yPosition);
xPosition += 70;
this.Controls.Add(btnArray[i]); // Add button to form.
}
//Creating cancel button
Button cancelButton = new Button();
cancelButton.Size = new Size(70, 23);
cancelButton.Text = “Cancel”;
cancelButton.Location = new Point(90, 80);
this.Controls.Add(cancelButton);
cancelButton.Click += new EventHandler(cancel_Click);
//Creating accept button
Button acceptButton = new Button();
acceptButton.Size = new Size(70, 23);
acceptButton.Text = “Accept”;
acceptButton.Location = new Point(0, 0);
this.Controls.Add(acceptButton);
//Handling Button clicks
btnArray[0].Click += new EventHandler(button_Click_0);
btnArray[1].Click += new EventHandler(button_Click_1);
btnArray[2].Click += new EventHandler(button_Click_2);
btnArray[3].Click += new EventHandler(button_Click_3);
}
private void button_Click_0(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.Visible = false;
btnArray[1].Visible = true;
btnArray[2].Visible = true;
btnArray[3].Visible = true;
}
private void button_Click_1(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.Visible = false;
btnArray[3].Visible = true;
btnArray[0].Visible = true;
btnArray[2].Visible = true;
}
private void button_Click_2(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.Visible = false;
btnArray[0].Visible = true;
btnArray[1].Visible = true;
btnArray[3].Visible = true;
}
private void button_Click_3(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.Visible = false;
btnArray[0].Visible = true;
btnArray[1].Visible = true;
btnArray[2].Visible = true;
}
private void cancel_Click(object sender, EventArgs e)
{
Close();
}
}
}
OUTPUT-