问候,我正在尝试在一个PictureBox集合上实现一个图像翻转,这些集合放置在一个tablelayoutpanel中,每个表格单元格中有一个。
下面是我的代码:
HomePicBox[picBoxCount].MouseEnter += new System.EventHandler(this.PictureBox_MouseEnter);
HomePicBox[picBoxCount].MouseLeave += new System.EventHandler(this.PictureBox_MouseLeave);==================
private void PictureBox_MouseEnter(object sender, EventArgs e)
{
Point p = HomeTableLayoutPanel.PointToClient(Control.MousePosition);
PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(p));
if (HomeCurrentPicBox == null)
return;
TableLayoutPanelCellPosition HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);
if (GameModel.HomeCellStatus(HomeCurrentPosition.Column, HomeCurrentPosition.Row) == Cell.cellState.Water)
{
HomeCurrentPicBox.Image = Properties.Resources.Scan;
HomeCurrentPicBox.Refresh();
gameFormToolTip.SetToolTip(HomeCurrentPicBox, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row);
}
}
private void PictureBox_MouseLeave(object sender, EventArgs e)
{
Point p = HomeTableLayoutPanel.PointToClient(Control.MousePosition);
PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(p));
if (HomeCurrentPicBox == null)
return;
TableLayoutPanelCellPosition HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);
if (GameModel.HomeCellStatus(HomeCurrentPosition.Column, HomeCurrentPosition.Row) == Cell.cellState.Water)
{
HomeCurrentPicBox.Image = Properties.Resources.Water;
HomeCurrentPicBox.Refresh();
gameFormToolTip.SetToolTip(HomeCurrentPicBox, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row);
}
}但是翻转不起作用!关于如何正确实现这一点,您有什么想法吗?
提前谢谢。
以下内容:
private void PictureBox_MouseEnter(object sender, EventArgs e)
{
PictureBox HomeCurrentPicBox = ((PictureBox)(sender));
HomeCurrentPicBox.Image = Properties.Resources.Scan;
TableLayoutPanelCellPosition HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);
gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row);
}
private void PictureBox_MouseLeave(object sender, EventArgs e)
{
PictureBox HomeCurrentPicBox = ((PictureBox)(sender));
HomeCurrentPicBox.Image = Properties.Resources.Water;
TableLayoutPanelCellPosition HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);
gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row);
}它会将图像滚动到右侧,但不会显示工具提示。如果我在工具提示中声明HomeCurrentPicBox而不是HomeTableLayoutPanel,它会错误地显示。
好吧,不,我想它起作用了。我必须更改工具提示的AutomaticDelay值。
谢谢大家。
发布于 2010-03-01 21:07:28
下面的代码应该可以工作:
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
((PictureBox)sender).ImageLocation = "Resources/logo.png";
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
((PictureBox)sender).ImageLocation = "Resources/logoonly.png";
}编辑:请注意,我正在使用ImageLocation更改图片,你可以使用任何你喜欢的东西,你可以使用' image‘属性代替ImageLocation,如果你愿意,可以给它分配一个图像。
https://stackoverflow.com/questions/2355885
复制相似问题