MWControls v1.0.3.0


This latest version includes a Multi Select TreeView Control which lets you choose between a few different ways of selecting TreeNodes.

There is a test project set up (MWControlsTest) for testing all of the MWControls.

MWControls contains:

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.

Shortcomings:

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:

version 1.0.3.0
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 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. and 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.

version 1.0.2.0
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.

version 1.0.1.0
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.

version 1.0.0.0
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.

Disclaimer:
Mikael Wiberg 2003

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. Feel free to donate any amount of money if this code makes you happy ;) Use this code at your own risk.

Up Next
    Ebook Download
    View all
    Learn
    View all