iTEgg
iTEgg

Reputation: 8340

C# ToolTip Problem

i have the following code that does a image rollover on pictureboxes located inside a table. each table cell has a picturebox in it.

the problem being even when in the code it is stated that no tooltip over the picturebox should be displayed, somehow some tooltips show up. i cant find it in the code as the code specifies no tooltips!

i have tried several approaches but they all seem to collasp when tooltips are used.. is there a known bug in ToolTip control?

    private bool deployingShip = false;

    private void PictureBox_MouseEnter(object sender, EventArgs e)
    {
        PictureBox HomeCurrentPicBox = ((PictureBox)(sender));
        TableLayoutPanelCellPosition HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);

        RefreshHomeGrid();

        if (deployingShip == false)
        {
            if (GameModel.HomeCellStatus(HomeCurrentPosition.Column, HomeCurrentPosition.Row) == Cell.cellState.Water)
            {
                HomeTableLayoutPanel.Cursor = Cursors.Hand;
                HomeCurrentPicBox.Image = Properties.Resources.Scan;
                HomeCurrentPicBox.Refresh();
            }
            else
            {
                HomeTableLayoutPanel.Cursor = Cursors.No;
                HomeTableLayoutPanel.Refresh();
            }
            gameFormToolTip.SetToolTip(HomeCurrentPicBox, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row);
         }

        if (deployingShip == true)
        {
            Cell.cellState state = GameModel.HomeCellStatus(HomeCurrentPosition.Column, HomeCurrentPosition.Row);
            switch (state)
            {
                case Cell.cellState.Origin:
                    HomeTableLayoutPanel.Cursor = Cursors.Hand;
                    gameFormToolTip.SetToolTip(HomeCurrentPicBox, currentShip.ToString() + ": " + Cell.cellState.Origin);
                    break;

                case Cell.cellState.EndPoint:
                    HomeTableLayoutPanel.Cursor = Cursors.Hand;
                    gameFormToolTip.SetToolTip(HomeCurrentPicBox, currentShip.ToString() + ": " + Cell.cellState.EndPoint);
                    break;
                default:
                    HomeTableLayoutPanel.Cursor = Cursors.No;
                    HomeTableLayoutPanel.Refresh();
                    return;
            }
        }
    }

    private void PictureBox_MouseLeave(object sender, EventArgs e)
    {
        PictureBox HomeCurrentPicBox = ((PictureBox)(sender));
        TableLayoutPanelCellPosition HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);

        if (GameModel.HomeCellStatus(HomeCurrentPosition.Column, HomeCurrentPosition.Row) == Cell.cellState.Water)
        {
            HomeCurrentPicBox.Image = Properties.Resources.Water;
            HomeCurrentPicBox.Refresh();
        }
    }

thank you, i fear you wont be able to find the bug from this submitted code :(

Upvotes: 0

Views: 1151

Answers (1)

John Laffoon
John Laffoon

Reputation: 2915

Are you missing the call to explicitly remove old values from the tooltip? Based on the code, I'm guessing it would probably belong in the MouseLeave event handler.

gameFormToolTip.SetToolTip(HomeCurrentPicBox, ""); 

Upvotes: 2

Related Questions