C#图书馆座位选定变色
时间: 2024-01-14 12:03:18 浏览: 20
以下是一个C图书馆座位选定变的示例代码:
```csharp
// 定义一个枚举类型,表示座位状态
enum SeatStatus
{
Available, // 可用
Selected, // 已选
Occupied // 已占用
}
// 定义一个座位类
class Seat
{
public int Row { get; set; } // 行号
public int Column { get; set; } // 列号
public SeatStatus Status { get; set; } // 座位状态
public Seat(int row, int column)
{
Row = row;
Column = column;
Status = SeatStatus.Available; // 初始状态为可用
}
}
// 在窗体中定义一个二维数组,表示所有座位
Seat[,] seats = new Seat[10, 10];
// 在窗体的构造函数中初始化所有座位
public Form1()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
seats[i, j] = new Seat(i, j);
}
}
}
// 在窗体中定义一个按钮的点击事件,表示选中某个座位
private void button1_Click(object sender, EventArgs e)
{
// 假设选中第3行第4列的座位
int row = 2;
int column = 3;
// 将该座位状态设置为已选
seats[row, column].Status = SeatStatus.Selected;
// 在界面上将该座位的背景色设置为黄色
Button btn = (Button)this.Controls.Find("button" + (row * 10 + column + 1), true)[0];
btn.BackColor = Color.Yellow;
}
```