chewlf
asked on
Dropdown tooltip for C#.NET
Hi All,
I need some helps. How to write in C#.NET on dropdownlist web control to display tooltip? I need this because some of the values inside the dropdownlist are too long, so I am thinking to display them into tooltip. Please help to provide solution code.
Thanks in advance.
Chew
I need some helps. How to write in C#.NET on dropdownlist web control to display tooltip? I need this because some of the values inside the dropdownlist are too long, so I am thinking to display them into tooltip. Please help to provide solution code.
Thanks in advance.
Chew
ASKER
Hi Vickram,
Thank you for your response. Would you please let me know how to write the code if I would like to display the tooltip using variable and the values might be different. From your example above, the tooltip is hardcoded. Please advice.
Thanks,
Chew
Thank you for your response. Would you please let me know how to write the code if I would like to display the tooltip using variable and the values might be different. From your example above, the tooltip is hardcoded. Please advice.
Thanks,
Chew
ASKER
I found this code somewhere. Anyone know how to convert it to web control?
//Code Start
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServ ices;
namespace ListBoxToolTips
{
/// <summary>
///
/// </summary>
public class ToolTipListBox : System.Windows.Forms.ListB ox
{
[StructLayout(LayoutKind.S equential) ]
public struct SIZE
{
public int cx;
public int cy;
}
[DllImport("gdi32.dll")]
public static extern int GetTextExtentPoint32(IntPt r hdc,
String str, int len, ref SIZE size);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd,IntPtr hdc);
public ToolTipListBox()
{
tp.InitialDelay = 500;
tp.ReshowDelay = 500;
tp.AutoPopDelay = 3000;
tp.Active = true;
}
protected override void OnMouseMove(System.Windows .Forms.Mou seEventArg s e)
{
int index = IndexFromPoint(e.X,e.Y);
if(index != ListBox.NoMatches )
{
if( LastIndex != index )
{
string s = Items[index].ToString();
IntPtr hdc = GetDC(this.Handle);
SIZE size;
size.cx = 0;
size.cy = 0;
GetTextExtentPoint32(hdc,s ,s.Length, ref size);
ReleaseDC(this.Handle,hdc) ;
if(this.Width < size.cx)
tp.SetToolTip(this,s);
LastIndex = index;
}
}
}
private ToolTip tp = new ToolTip();
private int LastIndex = -1;
}
}
//Code End
Please help.
Thanks,
Chew
//Code Start
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServ
namespace ListBoxToolTips
{
/// <summary>
///
/// </summary>
public class ToolTipListBox : System.Windows.Forms.ListB
{
[StructLayout(LayoutKind.S
public struct SIZE
{
public int cx;
public int cy;
}
[DllImport("gdi32.dll")]
public static extern int GetTextExtentPoint32(IntPt
String str, int len, ref SIZE size);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd,IntPtr hdc);
public ToolTipListBox()
{
tp.InitialDelay = 500;
tp.ReshowDelay = 500;
tp.AutoPopDelay = 3000;
tp.Active = true;
}
protected override void OnMouseMove(System.Windows
{
int index = IndexFromPoint(e.X,e.Y);
if(index != ListBox.NoMatches )
{
if( LastIndex != index )
{
string s = Items[index].ToString();
IntPtr hdc = GetDC(this.Handle);
SIZE size;
size.cx = 0;
size.cy = 0;
GetTextExtentPoint32(hdc,s
ReleaseDC(this.Handle,hdc)
if(this.Width < size.cx)
tp.SetToolTip(this,s);
LastIndex = index;
}
}
}
private ToolTip tp = new ToolTip();
private int LastIndex = -1;
}
}
//Code End
Please help.
Thanks,
Chew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
protected void ddlDropDown_PreRender(obje
{
ddlDropDown.Attributes.Add
}