2010-04-07 44 views
0

我在這裏由於Button_Click事件中的奇怪行爲。該代碼已附加。C#StripStatusText更新問題

問題是第一個StripStatus消息從不顯示。任何想法爲什麼?

private void FireBtn_Click(object sender, EventArgs e) 
    { 
     // Control local controls for launching attack 
     AwayTableLayoutPanel.Enabled = false; 
     AwayCancelBtn.Enabled = false; 
     FireBtn.Enabled = false; 


     ////////////// Below statusBar message is never displayed but the folowing sound clip is. 
     GameToolStripStatusLabel.Text = "(Home vs. Away)(Attack Coordinate: (" + 
      GameModel.alphaCoords(GridLock.Column) + "," + GridLock.Row + "))(Action: Fire)"; 
     //////////////////////////////////////////// 

     if (audio) 
     { 
      SoundPlayer fire = new SoundPlayer(Properties.Resources.fire); 
      fire.PlaySync(); 
      fire.Dispose(); 
     } 


     // compile attack message 
     XmlSerializer s; 
     StringWriter w; 

     FireGridUnit fireGridUnit = new FireGridUnit(); 
     fireGridUnit.FireGridLocation = GridLock; 

     s = new XmlSerializer(typeof(FireGridUnit)); 
     w = new StringWriter(); 
     s.Serialize(w, fireGridUnit); 


     ////////////////////////////////////////////////////////// 
     // send attack message 
     GameMessage GameMessageAction = new GameMessage(); 
     GameMessageAction.gameAction = GameMessage.GameAction.FireAttack; 
     GameMessageAction.statusMessage = w.ToString(); 

     s = new XmlSerializer(typeof(GameMessage)); 
     w = new StringWriter(); 
     s.Serialize(w, GameMessageAction); 
     SendGameMsg(w.ToString()); 

     GameToolStripStatusLabel.Text = "(Home vs. Away)(Attack Coordinate: (" + 
      GameModel.alphaCoords(GridLock.Column) + "," + GridLock.Row + "))(Action: Awaiting Fire Result)"; 

    } 

編輯:如果我在StripStatus消息之後放入消息框狀態更新。

+0

@克里斯:聲音樣本效力於近2秒鐘,這樣的狀況應該已經先並用大量的更新時間。 – iTEgg 2010-04-07 13:24:44

回答

1

有一個很多的東西在你分配了Text屬性之後。在Click事件處理程序完成執行之前,標籤不會在視覺上更新。它的Paint事件不能運行,直到UI線程再次空閒。

你可以迫使它通過調用條的更新()方法馬上漆:

GameToolStripStatusLabel.Text = "..."; 
GameToolStrip.Update(); 
+0

hey nobugz!一如既往的出色! :) – iTEgg 2010-04-07 13:29:30