Tooltips for CheckedListBox items?

后端 未结 5 748
盖世英雄少女心
盖世英雄少女心 2021-01-17 10:20

Is there a straighforward way to set additional text to appear in a tooltip when a user\'s mouse is held over an item in a CheckedListBox?

What I would expect

5条回答
  •  感动是毒
    2021-01-17 10:37

    Add a Tooltip object to your form and then add an event handler for the CheckedListBox.MouseHover that calls a method ShowToolTip(); Add MouseMove event of your CheckedListBox which has the following code:

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

    Then create the ShowToolTip method:

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

提交回复
热议问题