C#围绕winform的行和列的动态标签

时间:2017-04-03 09:02:28

标签: c# winforms entity-framework

我正在开发酒店软件,我希望在运行时显示带有标签的WinForm上的所有房间。房间状态将从数据库中拉出,标签的颜色将根据房间状态而变化。请问如何创建这个。

下面是我想要实现的表单布局的示例。

Example of the form layout

编辑:

private void Charts(GroupBox group, Label label, string roomNo)
    {
        var room = RoomServices.CheckRoom(roomNo);

        MessageBox.Show(Convert.ToString(room.Id));

        try
        {
            if (room.RoomStatusId == 4)
            {
                group.BackColor = Color.Red;
                group.ForeColor = Color.White;
                group.Text = roomNo;
                var c = RoomServices.FindCheckIn(room.Id);

                string name = c.Guest.FirstName + " " + c.Guest.Surname;
                label.Text = name;

            }
            else if (room.RoomStatusId == 3)
            {
                group.BackColor = Color.Orange;
                group.ForeColor = Color.White;
                group.Text = roomNo;
                label.Text = "OUT of Order";

            }
            else if (room.RoomStatusId == 2)
            {
                group.BackColor = Color.Brown;
                group.ForeColor = Color.White;
                group.Text = roomNo;
                label.Text = "Room Dirty";
            }
            else if (room.RoomStatusId == 5)
            {
                group.BackColor = Color.Coral;
                group.ForeColor = Color.White;
                group.Text = roomNo;
                label.Text = "Room Reserved";
            }
            else
            {
                group.BackColor = Color.Green;
                group.ForeColor = Color.White;
                group.Text = roomNo;
                label.Text = "Room Arrival";
            }

        }
        catch (Exception ex)
        {

            MessageBox.Show(ex.Message);
        }

    }

1 个答案:

答案 0 :(得分:0)

使用UserControl和FlowLayoutPanel来解决此问题