C# ListBox内容过长无法完全显示,添加ToolTip控件
#region C# ListBox内容过长无法完全显示,添加ToolTip控件
ToolTip toolTip = new ToolTip();
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.MSGListBox.SelectedIndices.Count > 0)
{
this.toolTip.Active = true;
this.toolTip.SetToolTip(this.MSGListBox, this.MSGListBox.Items[this.MSGListBox.SelectedIndex].ToString());
}
else
{
this.toolTip.Active = false;
}
}
private void MSGListBox_MouseMove(object sender, MouseEventArgs e)
{
int index = MSGListBox.IndexFromPoint(e.Location);
if (index != -1 && index < MSGListBox.Items.Count)
{
if (toolTip.GetToolTip(MSGListBox) != MSGListBox.Items[index].ToString())
{
toolTip.SetToolTip(MSGListBox, MSGListBox.Items[index].ToString());
}
}
}