C# ListBox内容过长无法完全显示,添加ToolTip控件,提示这一项的完整内容

首先添加一个ListBox和一个ToolTip,ListBox添加SelectedIndexChanged事件

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedIndices.Count > 0)
            {
                this.toolTip1.Active = true;

                this.toolTip1.SetToolTip(this.listBox1, this.listBox1.Items[this.listBox1.SelectedIndex].ToString());
            }
            else
            {
                this.toolTip1.Active = false;
            }
        }

 

效果如下:

C# ListBox内容过长无法完全显示,添加ToolTip控件,提示这一项的完整内容