0
我已经创建了我自己的自定义控件,在这里我想将此自定义控件设置为其他控件的工具提示。所以我必须添加代码,以通过SendMessage的方式通过下面的代码设置的自定义控制,工具提示,SendMessage无法设置工具提示窗口
public class MyControl : Control
{
Dictionary<IntPtr, Component> m_tools;
TOOLINFO m_toolInfo;
public MyControl()
{
m_tools = new Dictionary<IntPtr, Component>();
m_toolInfo = new TOOLINFO();
}
string myTipText;
public string MyTipText
{
get
{
return myTipText;
}
set
{
myTipText = value;
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
SolidBrush brush = new SolidBrush(Color.Blue);
e.Graphics.DrawString(this.MyTipText, this.Font, brush, e.ClipRectangle.Location);
}
internal void AddControl(Component component)
{
if (component != null)
{
if (component is Control)
{
Control control = component as Control;
control.HandleCreated += control_HandleCreated;
if (control.IsHandleCreated)
{
control_HandleCreated(control, EventArgs.Empty);
}
}
}
}
void control_HandleCreated(object sender, EventArgs e)
{
Control control = sender as Control;
if(control!=null)
{
m_tools[control.Handle] = control;
m_toolInfo.hwnd = this.Handle;
m_toolInfo.uId = control.Handle;
**int result = WindowsAPI.SendMessage(this.Handle, (int)TTM.TTM_ADDTOOLW, 0, ref m_toolInfo);**
}
}
}
但以失败SendMessage函数的结果。我可否知道,为什么自定义控件未能设置为控件的工具提示?
这里是SendMessage函数,
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError=true)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref TOOLINFO lParam);
我找不到失败的原因。请任何人都帮助我。
问候, 阿迈勒拉吉U.