簡體   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