WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
- MWTreeView: A Multi Select TreeView Control (MultiSelect, Multi-Select)
- MWScrollLabel: A Label Control that scrolls the text back and forth if it does not fit when the mouse is hovering over it.
The MWScrollLabel Control also supports displaying the text in different directions: Normal, UpsideDown, Left, and Right.
- MWLabel: A Label Control that uses StringFormat.GenericTypographic, meaning that the text doesn't require a large blank area next to it.
The MWLabel Control also supports displaying the text in different directions: Normal, UpsideDown, Left, and Right.
Coding Technologies Used
|MWTreeView||Multi Select for TreeNodes.|
Overridden CancelEventArgs so that AfterXXX and BeforeXXX EventHandlers can be set up allowing the programmer to cancel setting properties.
|MWScrollLabel||A timer is used for the scrolling.|
|MWLabel and MWScrollLabel||GDI+ is used to draw everything (text and image).|
The text is rendered properly as disabled when the Enabled property is set to false.
A graphical Design Time Editor imheriting from UITypeEditor is used for the TextDir property.
|All||Inheritance including overriding EventHandlers and programming around the fact that some methods etc in the parent Control are hidden.|
MWLabel and MWScrollLabel: The UseMnemonic property is not used. (I don't intend to fix this myself. If someone has a solution, please let me know.)
MWTreeView: When HotTracking is turned on, the colors are not correct. (I will probably not fix this myself. If someone has a solution, please let me know.)
Version History and More about the Controls
There are a lot of updates to MWTreeView.
MWTreeView The MWTreeView Control supports proper Multi Select functionality. When I say "proper," I mean better than any other free one I have seen out there (C# or other).
MultiSelect is a property of the MWTreeView Control and can be set to one of the following values:
- NoMulti: Multi Selection is turned off. All other features are still available though, so it still works better than a normal TreeView Control.
- Multi: Free unrestricted Multi Selection—any TreeNodes can be selected.
- MultiSameBranchAndLevel: Multiple TreeNodes can only be selected if they are in the same branch and on the same level.
- MultiSameBranch: Multiple TreeNodes can only be selected if they are in the same branch.
- MultiSameLevel: Multiple TreeNodes can only be selected if they are on the same level.
Several keys now do things to the MWTreeView: Ctrl-A selects all TreeNodes (according to the restrictions imposed by the MultiSelect property), etc, etc.
TreeNodes can be selected by using the mouse in combination with the Control, Shift, and Alt keys.
If the MultiSelect property is set to a value other than NoMulti, no TreeNode has to be selected at all. Once one is selected, it can be deselected (Control and mouse click).
The FullRowSelect property of the original TreeView Control didn't seem to work (please correct me if I'm wrong). It has now been implemented.
There is a massive amount of code (more than 3400 lines in the MWTreeView class alone), so I guess this is an example (hopefully a good one) of how to subclass a Control and add a lot of functionality.
MWControlsTest The MWControlsTest project has been added, making it really easy to test all the features of the MWControls. Any new Controls added to MWControls can appear on a new TabPage.
MWScrollLabel The MWScrollLabel is a subclassed Label Control that can be set to scroll the text back and forth if the whole text does not fit. The way I am using this is by starting the scrolling when the mouse is hovering over the Control. There are quite a few options that can be set to control the scrolling.
Note that the MWScollLabel Control is only displaying its text on one line. This is intentional and, coupled with its scrolling capabilities, is really the whole reason for implementing this Control.
MWLabel The StringFormat used by the text can be set to one of two options: GenericDefault and GenericTypographic.
- GenericDefault: This is the StringFormat used by the original Label Control.
- GenericTypographic: This StringFormat is much more precise when it comes to measuring the string.
Using the GenericTypographic option (default) means that if the text is right-aligned, it will indeed properly align to the right even for very long words with no white-space.
The Text Direction can be set:
- Normal: Normal horizontal text.
- UpsideDown: Horizontal text displayed upside down.
- Left: Vertical Text that can be read by tilting your head to the left.
- Right: Vertical Text that can be read by tilting your head to the right.
There is an option of displaying an image (the normal Image property or the image from the ImageIndex property) over the text or like the normal Label Control under the text.
The image (the normal Image property or the Image from the ImageIndex property), if one is used, is displayed very close to the applicable edge—not some strange arbitrary distance from the edge.
Copyright © Mikael Wiberg 2003
email@example.com (usual HoTMaiL spam filters)
firstname.lastname@example.org (heavy spam filters on, hardly anything gets through; start the subject with C# and it will probably go through)
email@example.com (heavy spam filters on, hardly anything gets through; start the subject with C# and it will probably go through)
Feel free to use this code as you wish, as long as you do not take credit for it yourself. If it is used in commercial projects or applications, please mention my name. Use this code at your own risk. If your machine blows up while using it—don't blame me.
About the Author
Mikael Wiberg, born in Sweden, currently lives in Australia. He has a Master of Computing Science degree and have been using C# for a couple of years. His C# expertise is mainly in the fields of GUIs, graphics, GDI+, a lot of 'normal' WindowsForms, but also ASPX and MS SQL and Oracle programming. Also some DirectX v9.0—he wishes there was more of that.