
Introduction
This TreeView is Windows standard treeview but has no default interaction to user mouse actions.
Even selecting, expanding or collapsing node is are all blocked. So you have to implement them yourself.
So, what's good for this? That's the event handling timing. Because reaction code is implemented yourself, you can know when the reaction raises, and also can control whether those reactions operated or not.
In my case, my application have to block expanding node by only mouse action. But the default TreeView control's BeforeExpand event does not pass right reason. The expanding from mouse click is passed as 'Unknown' reason event. So I couldn't use that. And finally I found this way.
What this code does
This code offers derived TreeView class that does not react any user's mouse action. And those reaction can be implemented easily in default mouse event handler.
How this does
This class blocks Windows mouse messages from DefWndProc() method, so those reaction code does not fires. However, I do not know detailed behavior about this. This just works. See next section for more information.
How to use this
You can just use this control directly on your windows form. But I do not recommend that. This class is just show-sample, So I recommend you implement this behavior youself.
Implementation is simple. Derive a TreeView and override DefWndProc().
And ignore all mouse messages. (Do not call base.DefWndProc() when the message code is mouse related.) I defined mouse messages in NativeMethod class. You can refer my sample project.
protected override void DefWndProc(ref Message m)
{
if (!react)
{
NativeMethods.MouseMessages mm = (NativeMethods.MouseMessages)m.Msg;
switch (mm)
{
case NativeMethods.MouseMessages.WM_LBUTTONDBLCLK: return;
case NativeMethods.MouseMessages.WM_LBUTTONDOWN: return;
case NativeMethods.MouseMessages.WM_LBUTTONUP: return;
case NativeMethods.MouseMessages.WM_MBUTTONDBLCLK: return;
case NativeMethods.MouseMessages.WM_MBUTTONDOWN: return;
case NativeMethods.MouseMessages.WM_MBUTTONUP: return;
case NativeMethods.MouseMessages.WM_RBUTTONDBLCLK: return;
case NativeMethods.MouseMessages.WM_RBUTTONDOWN: return;
case NativeMethods.MouseMessages.WM_RBUTTONUP: return;
}
}
base.DefWndProc(ref m);
}
Or you can just copy the source code into your project. Modify it as you want.
Because the .NET Control's mouse event is raised in another place, (maybe WndProc() method), you will get those mouse event normally even the messages are ignored.
However, I do not know detailed behavior of those Windows Messages.
Do not ask me any background behavior of those message. I don't know too.
This is JUST WORK sample. Of course I cannot guarantee anything work perfectly.
I post this text just to share my discorver.
Sample Project
The source and sample code is made with VCSE(Visual C# Express 2005). It contains VCSE project. But may work with VS. I did not tested.
P.S.
I'm not an English speaker, so main text can contain some wrong words. Thank you for your hard reading!