Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show me a tip!

Status
Not open for further replies.

stevensteven

Programmer
Jan 5, 2004
108
CA
Hello,

I have noticed on .NET controls such as a listbox, if an item is too large to fit into the listbox, there is no tool tip that shows the entire item.

Is there a way to turn this on??

Thanks for your help.

 
1. Add horizontal scrool bar to the listbox control
2. You can add a ToolTip object on the form and when an item is selected in the in the listbox show the whole item using tooltip:
3. When an item is selected in the listbox show the whole item in another control, let say a multiline text box.
4. There are also other solutions and here is an example for 2:
Code:
public class Form1 : System.Windows.Forms.Form
{
	private System.ComponentModel.IContainer components;
	private System.Windows.Forms.ListBox listBox1;
	private System.Windows.Forms.ToolTip toolTip1;
	this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);

	private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
	{
		if (listBox1.SelectedIndex != -1)
		{
			this.toolTip1.SetToolTip(listBox1, listBox1.SelectedItem.ToString());
		}
	}
}
The above solution could be modified to show the tooltip for the large items but there is some work.
Detect if the item is too large by using the listBox1.Size, the size of the font and the listBox1.SelectedItem.ToString().Length.
Code:
if (listBox1.SelectedIndex != -1 && listBox1.SelectedItem.ToString() > 25)
{
	this.toolTip1.SetToolTip(listBox1, listBox1.SelectedItem.ToString());
}
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top