2017-04-03 89 views
-1

我正在一家酒店軟件,我想在運行時顯示所有的房間在WinForm與標籤上。房間狀態將從數據庫中拉出,標籤的顏色將根據房間狀態而改變。請如何去創建這個。C#動態標籤跨行和列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); 
     } 

    } 
+0

不只是要求如何去說。本指南 – rilly009

+1

我給你一個指導:1-創建標籤並將它們添加到你的表單中2.-根據房間狀態改變顏色 – Pikoh

+0

剛剛學習c#的新手。我真的很困惑。 – rilly009

回答

0

使用用戶控件和FlowLayoutPanel的解決這個