繁体   English   中英

C#图像翻转

[英]C# Image RollOver

问候,即时通讯试图在一个PictureBox集合上实现图像翻转,该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值。

感谢大家。

以下应该工作:

    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并根据需要为其分配图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM