java settooltip_ComboBox的ToolTip显示(API方式)

namespace comboBoxApp

...{

/**

/// 可带ToolTip的组合框控件

///

public class ComboBoxEx : ComboBox

...{

/**

/// 这个子类窗口用来存放下拉列表窗口,通过它来操作下拉列表

///

private SubWindow m_SubWindow;

/**

/// 通常的构造函数

///

public ComboBoxEx()

...{

}

/**

/// 处理Windows的消息

///

///

protected override void WndProc(ref Message m)

...{

//通过这个消息可以得到下拉列表的窗口名柄

if (m.Msg == 0x210 && (int)m.WParam == 0x3e80001)

...{

//构建子类化窗口

SubWindow sw = new SubWindow();

//把当前ComboBox实例做为属性传入方便处理

sw.Owner = this;

//把得到的列表句柄关联到子类窗口类上。

sw.AssignHandle(m.LParam);

//这里的做用是保证子类窗口和ComboBoxEx生存期同步

this.m_SubWindow = sw;

}

base.WndProc(ref m);

}

/**

/// 重写以释放子类

///

///

protected override void Dispose(bool disposing)

...{

if (disposing && this.m_SubWindow != null)

...{

this.m_SubWindow.DestroyHandle();

}

base.Dispose(disposing);

}

}

/**

/// 子类化窗口的类

///

internal class SubWindow : NativeWindow

...{

/**

/// 为了得到列表上的鼠标坐标而使用Api函数及其所用到的数据结构

///

[StructLayout(LayoutKind.Sequential)]

public class POINT

...{

public int x;

public int y;

public POINT(int x, int y)

...{

this.x = x;

this.y = y;

}

}

/**

/// 映射窗体的坐标

///

/// 源窗口句柄

/// 要影射到的窗口句柄

/// 转换前后的坐标数据

///

///

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]

public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] POINT pt, int cPoints);

/**

/// 为了得到指定坐标下的项而需要向列表发送消息

///

///

///

///

///

///

[DllImport("user32.dll", CharSet = CharSet.Auto)]

public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

/**

/// 为了得到指定索引的列表的内容而需要向列表发送消息,因为列表文本可能被格式化,所以这是合理的。

///

///

///

///

///

///

[DllImport("user32.dll", CharSet = CharSet.Auto)]

public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, StringBuilder lParam);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值