简体   繁体   English

C#图像翻转

[英]C# Image RollOver

greetings, im trying to implement an image rollover on a collection of PictureBox (es) that are place in a tablelayoutpanel and one in each table cell. 问候,即时通讯试图在一个PictureBox集合上实现图像翻转,该PictureBox集合放置在tablelayoutpanel中,每个表格单元格中一个。

here is my code: 这是我的代码:

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);
        }
    }

but the rollover is not working! 但结转无效! any ideas as to how to implement this correctly? 关于如何正确实现这一点的任何想法?

thanks in advance. 提前致谢。

the following: 下列:

    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);
    }

it does the image rollover right but does not display the tooltip. 它会向右滚动图像,但不显示工具提示。 if i state HomeCurrentPicBox instead of HomeTableLayoutPanel on the tooltip it diplays wrongly. 如果我在工具提示上声明HomeCurrentPicBox而不是HomeTableLayoutPanel,则会显示错误。

okay no it works i think. 好吧不行,我认为。 i had to change the AutomaticDelay value of the tooltip. 我不得不更改工具提示的AutomaticDelay值。

thanks everyone. 感谢大家。

The Following should work: 以下应该工作:

    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";
    }

Edit: Note that I am using ImageLocation to change the pictures, you can use anything you like, you can use the 'Image' property instead of the ImageLocation and assign an image to it if you wish. 编辑:请注意,我正在使用ImageLocation更改图片,可以使用任何您喜欢的东西,可以使用'Image'属性代替ImageLocation并根据需要为其分配图像。

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

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