Click here to Skip to main content
15,885,660 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I am working on a C#.Net Windows application and I want to display tool tips for every item in a combobox as the text is getting clipped for some of the items. This is what I am presently doing in my code :

private void Form2_Load(object sender, EventArgs e)
{
    comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
}

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    string text = comboBox1.GetItemText(comboBox1.Items[e.Index]);
    e.DrawBackground();
    using (SolidBrush br = new SolidBrush(e.ForeColor))
    { e.Graphics.DrawString(text, e.Font, br, e.Bounds); }
    if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
    { toolTip1.Show(text, comboBox1, e.Bounds.Right, e.Bounds.Bottom); }
    e.DrawFocusRectangle();
}

private void comboBox1_DropDownClosed(object sender, EventArgs e)
{
    toolTip1.Hide(comboBox1);
}



The problem I am facing here is that if the comboBox is located near the edge of the form(the form opens in maximized mode), the tool tip flickers.

Please suggest a solution.

Thanks in advance.

Gitika Khurana
Posted
Updated 18-Jul-12 19:24pm
v2

1 solution

Hi,

set DoubleBuffered property of the form to True on Form_Load.

this.DoubleBuffered = true;


This will remove the flickering.

Hope this helps.

Happy Coding :)
 
Share this answer
 
Comments
CodeDZStar 19-Jul-12 3:05am    
my 5+!
Sunny_Kumar_ 19-Jul-12 3:06am    
thanks
gitika.khurana 20-Jul-12 5:59am    
That did not work for me.

From what I can observe, I think there aint enough space to the right of the point where the tooltip is being drawn, thats why it keeps on re-drawing the tool-tip over and over, hence the flickering. I have tried relocating the tool tip to middle of the form and it works fine.
Sunny_Kumar_ 20-Jul-12 6:16am    
yeah, you're right, that may be the case of problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900