tags:

views:

207

answers:

1

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

+2  A: 

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, ""); 
John L.
tested for now! thank you for bringing SetToolTip behaviour to clarity! that was it. thanks many many times.
iEisenhower
It's always bugged me that ToolTip doesn't have a clear command. Also, shouldn't "" be `String.Empty`?
R. Bemrose
yea i used string.empty but John L. provided a solid solution.
iEisenhower