I am here due to a strange behaviour in Button_Click event. The code is attached.
The issue is the first StripStatus message is never displayed. any ideas as to why?
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.Ser开发者_如何学Pythonialize(w, GameMessageAction);
SendGameMsg(w.ToString());
GameToolStripStatusLabel.Text = "(Home vs. Away)(Attack Coordinate: (" +
GameModel.alphaCoords(GridLock.Column) + "," + GridLock.Row + "))(Action: Awaiting Fire Result)";
}
EDIT: if I put in a messageBox after the StripStatus message the status is updated.
There's a lot of stuff going on after you assigned the Text property. The label will not visually update until the Click event handler is done executing. It's Paint event cannot run until the UI thread goes idle again.
You can force it to paint right away by calling the strip's Update() method:
GameToolStripStatusLabel.Text = "...";
GameToolStrip.Update();
精彩评论