开发者

Tooltip steals mouse click

开发者 https://www.devze.com 2022-12-30 11:17 出处:网络
I\'m writing a custom TreeView from ScrollableControl. I decided to show tooltips when the mouse hovers over nodes with text too long to display.

I'm writing a custom TreeView from ScrollableControl. I decided to show tooltips when the mouse hovers over nodes with text too long to display.

I find that when tooltips are shown, the user is not 开发者_StackOverflow中文版able to click the node to select it because (I think) he's clicking the tooltip window, not my control.

Is there any easy solutions? As far I can see, System.Windows.Forms.TreeView don't have this problem. Thanks!


You need to override WndProc in your tooltip form and return HT_TRANSPARENT in response to the WM_NCHITTEST message.

For example:

protected override void DefWndProc(ref Message m) {
    switch (m.Msg) {
        case 0x84://WM_NCHITTTEST
            m.Result = new IntPtr(-1);  //HT_TRANSPARENT
            return;
    }
    base.DefWndProc(ref m);
}

This will make Windows believe that your from is invisible to the mouse, causing any mouse events to be passed to the window underneath it. (But only if both windows are from the same process)

0

精彩评论

暂无评论...
验证码 换一张
取 消