C#图像翻转
您好,我正在尝试在一组PictureBox上实现图像滚动,这些PictureBox位于tablelayoutpanel中,每个表单元格中各有一个 这是我的密码:C#图像翻转,c#,image,rollover,C#,Image,Rollover,您好,我正在尝试在一组PictureBox上实现图像滚动,这些PictureBox位于tablelayoutpanel中,每个表单元格中各有一个 这是我的密码: HomePicBox[picBoxCount].MouseEnter += new System.EventHandler(this.PictureBox_MouseEnter); HomePicBox[picBoxCount].MouseLeave += new System.EventHandler(this.PictureBox
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,它会错误地显示
好吧,不,我想它行得通。我必须更改工具提示的自动延迟值
谢谢大家。以下几点应该有用:
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,并根据需要为其指定一个图像。是否已在调试器中插入代码?它是否转到设置新图像的行?这很好。这将需要一些时间来实现它,但我正在寻找一些将使用“发件人”。谢谢。您提供的代码适用于滚动。但是当我尝试在该控件上设置工具提示时。。好吧,提示没有显示。有什么想法吗?谢谢。我还没有编写工具提示代码,所以我无法在这方面帮助您,它也能工作,所以我不会研究它:)很高兴我能提供帮助