0

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 :(

1 Answer 1

2

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, ""); 
Sign up to request clarification or add additional context in comments.

3 Comments

tested for now! thank you for bringing SetToolTip behaviour to clarity! that was it. thanks many many times.
It's always bugged me that ToolTip doesn't have a clear command. Also, shouldn't "" be String.Empty?
yea i used string.empty but John L. provided a solid solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.