C#工具提示问题
我有下面的代码,它对位于表中的PictureBox执行图像滚动。每个表格单元格中都有一个picturebox 问题是,即使在代码中声明不应在picturebox上显示工具提示,也会以某种方式显示一些工具提示。我在代码中找不到它,因为代码没有指定工具提示 我尝试过几种方法,但当使用工具提示时,它们似乎都会崩溃。。工具提示控件中是否存在已知错误C#工具提示问题,c#,tooltip,C#,Tooltip,我有下面的代码,它对位于表中的PictureBox执行图像滚动。每个表格单元格中都有一个picturebox 问题是,即使在代码中声明不应在picturebox上显示工具提示,也会以某种方式显示一些工具提示。我在代码中找不到它,因为代码没有指定工具提示 我尝试过几种方法,但当使用工具提示时,它们似乎都会崩溃。。工具提示控件中是否存在已知错误 private bool deployingShip = false; private void PictureBox_MouseEnte
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();
}
}
谢谢,我担心您无法从提交的代码中找到错误:(您是否错过了从工具提示中显式删除旧值的调用?根据代码,我猜它可能属于MouseLeave事件处理程序
gameFormToolTip.SetToolTip(HomeCurrentPicBox, "");
现在已经测试过了!谢谢你让SetToolTip行为变得清晰!就是这样。谢谢很多次。工具提示没有清晰的命令一直困扰着我。而且,不应该是
String.Empty
?是的,我使用了String.Empty,但John L.提供了一个可靠的解决方案。