C# TableLayoutPanel MouseLeave
-
greetings, i am developing a battleships clone game and i have an issue with TableLayoutPanel MouseLeave event. first 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; } }
this appears to function properly. now the MouseLeave event:
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(); }
this is acting strange. it goes through the code and even a "HI" is displayed but the PictureBox image is not changed to water. any ideas as to why? this does not happen all the time, only from time to time. what the above code is doing is basically scanning through the table cells and if the cell content is WATER then it updates the table cell image to SCAN and as the user moves onwards it is switching the cell image back to WATER. hope this is enough information. please ask if more is needed. thank you in advance.
-
greetings, i am developing a battleships clone game and i have an issue with TableLayoutPanel MouseLeave event. first 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; } }
this appears to function properly. now the MouseLeave event:
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(); }
this is acting strange. it goes through the code and even a "HI" is displayed but the PictureBox image is not changed to water. any ideas as to why? this does not happen all the time, only from time to time. what the above code is doing is basically scanning through the table cells and if the cell content is WATER then it updates the table cell image to SCAN and as the user moves onwards it is switching the cell image back to WATER. hope this is enough information. please ask if more is needed. thank you in advance.
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
}i wonder why are you using this
HomeLastPicBox = new PictureBox();
when you have already assigned the picture to this picture box in the if block. after displaying the message box you need to return. do it like this.
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
return;
}hope it helps.
Ahsan Ullah Senior Software Engineer MCTS 2.0
-
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
}i wonder why are you using this
HomeLastPicBox = new PictureBox();
when you have already assigned the picture to this picture box in the if block. after displaying the message box you need to return. do it like this.
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
return;
}hope it helps.
Ahsan Ullah Senior Software Engineer MCTS 2.0