Pau*_*art 15 c# user-interface tooltip checkedlistbox winforms
当用户的鼠标放在CheckedListBox中的项目上时,是否有一种直接的方法来设置其他文本出现在工具提示中?
我希望能够在代码中做到的是:
uiChkLstTables.DisplayOnHoverMember = "DisplayOnHoverProperty"; //Property contains extended details
Run Code Online (Sandbox Code Playgroud)
任何人都能指出我正确的方向吗?我已经找到了一些文章,涉及检测鼠标当前所在的项目并创建一个新的工具提示实例,但这听起来有点过于设计,不是最好的方法.
提前致谢.
Fer*_*min 19
向表单添加一个Tooltip对象,然后为CheckedListBox.MouseHover添加一个调用方法ShowToolTip()的事件处理程序; 添加CheckedListBox的MouseMove事件,其中包含以下代码:
//Make ttIndex a global integer variable to store index of item currently showing tooltip.
//Check if current location is different from item having tooltip, if so call method
if (ttIndex != checkedListBox1.IndexFromPoint(e.Location))
ShowToolTip();
Run Code Online (Sandbox Code Playgroud)
然后创建ShowToolTip方法:
private void ShowToolTip()
{
ttIndex = checkedListBox1.IndexFromPoint(checkedListBox1.PointToClient(MousePosition));
if (ttIndex > -1)
{
Point p = PointToClient(MousePosition);
toolTip1.ToolTipTitle = "Tooltip Title";
toolTip1.SetToolTip(checkedListBox1, checkedListBox1.Items[ttIndex].ToString());
}
}
Run Code Online (Sandbox Code Playgroud)