1

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 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!

dreeves
  • 26,430
  • 45
  • 154
  • 229
deerchao
  • 10,454
  • 9
  • 55
  • 60

1 Answers1

1

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)

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • I'm using System.Windows.Forms.Tooltip class to show tooltip, seems I can't override wndproc of the tooltip window. – deerchao May 14 '10 at 06:09
  • I managed to use my own form as tooltip windows. Your answer, and http://stackoverflow.com/questions/156046/show-a-form-without-stealing-focus-in-c helped a lot. – deerchao May 14 '10 at 10:51
  • If you use the `Tooltip` class, you shouldn't have this issue at all. – SLaks May 14 '10 at 13:47
  • I've tried that before walking to the hard way, but Tooltip class has its own issues. – deerchao May 15 '10 at 01:57