Pergunta

Saudações, estou tentando implementar uma rolagem de imagens em uma coleção de (s) PictureBox (s) que são colocadas em um tablelayoutPanel e uma em cada célula da tabela.

Aqui está o meu código:

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

Mas a capotagem não está funcionando! Alguma idéia de como implementar isso corretamente?

desde já, obrigado.

a seguir:

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

Ele faz a rolagem da imagem à direita, mas não exibe a dica de ferramenta. Se eu declarar o HomeCurrentpicBox em vez do HomeTableLayoutPanel na dica de ferramenta, ela é de forma incorreta.

Ok, não, funciona, eu acho. Eu tive que alterar o valor automático do Alay da dica de ferramenta.

Obrigado a todos.

Foi útil?

Solução

O seguinte deve funcionar:

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

Editar: Observe que estou usando o ImageLocation para alterar as imagens, você pode usar o que quiser, pode usar a propriedade 'Imagem' em vez da imageLocation e atribuir uma imagem a ela, se desejar.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top