C#ToolTip问题

时间:2010-03-01 18:33:52

标签: c# tooltip

我有以下代码在位于表格内的图片框上进行图像翻转。每个表格单元格中都有一个图片框。

问题是即使在代码中声明不应该显示图片框上的工具提示,不知何故一些工具提示出现。我无法在代码中找到它,因为代码没有指定工具提示!

我尝试了几种方法但是当使用工具提示时它们似乎都是collasp .. ToolTip控件中是否存在已知错误?

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

谢谢,我担心你无法从这个提交的代码中找到错误:(

1 个答案:

答案 0 :(得分:2)

您是否错过了从工具提示中明确删除旧值的调用?根据代码,我猜它可能属于MouseLeave事件处理程序。

gameFormToolTip.SetToolTip(HomeCurrentPicBox, "");