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.