問候,我正在開發一個戰艦克隆遊戲,並且我有一個TableLayoutPanel MouseLeave事件的問題。C#TableLayoutPanel MouseLeave
第一的MouseMove:
private PictureBox HomeLastPicBox = new PictureBox();
private TableLayoutPanelCellPosition homeLastPosition = new TableLayoutPanelCellPosition(0, 0);
private void HomeTableLayoutPanel_MouseMove(object sender, MouseEventArgs e)
{
PictureBox NowPicControl = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location));
if ((NowPicControl != null) && (NowPicControl != HomeLastPicBox))
{
HomeLastPicBox = (PictureBox)(HomeTableLayoutPanel.GetControlFromPosition(homeLastPosition.Column, homeLastPosition.Row));
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
}
TableLayoutPanelCellPosition homeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(NowPicControl);
if (GameModel.HomeCellStatus(homeCurrentPosition.Column, homeCurrentPosition.Row) == Cell.cellState.WATER)
{
NowPicControl.Image = Properties.Resources.scan;
}
homeLastPosition = homeCurrentPosition;
}
}
這似乎正常工作。
現在MouseLeave事件:
private void HomeTableLayoutPanel_MouseLeave(object sender, EventArgs e)
{
MessageBox.Show("col " + homeLastPosition.Column.ToString() + " row " + homeLastPosition.Row.ToString());
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
}
HomeLastPicBox = new PictureBox();
}
,這是舉止怪異。它會經過代碼,甚至會顯示「HI」,但PictureBox圖像不會變爲水。任何想法爲什麼?這不會一直髮生,只是不時發生。
上述代碼所做的基本上是掃描表格單元格,如果單元格內容是WATER,則它將表格單元格圖像更新爲SCAN,隨着用戶向前移動,它將單元格圖像切換回WATER。
希望這是足夠的信息。請詢問是否需要更多。
謝謝你提前。
p.s.這是嘗試像mouseover和mouseexit一樣的javascript。
我已經取得了一些進展。在鼠標離開後,MouseMove再次被調用,因此我遇到的結果。
只需要以另一種方式邏輯我認爲。