MWControls v1.0.3.0



Click here for a larger image.

Introduction

This latest version includes a Multi Select TreeView Control that lets you choose among a few different ways of selecting TreeNodes. There is a test project set up (MWControlsTest) to test 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

Command Description
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 v1.0.3.5

There are a lot of updates to MWTreeView.



Click here for a larger image.

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

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

Copyright © Mikael Wiberg 2003

mikwib@hotmail.com (usual HoTMaiL spam filters)
mick@ar.com.au (heavy spam filters on, hardly anything gets through; start the subject with C# and it will probably go through)
md5mw@mdstud.chalmers.se (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.

mick@ar.com.au
mikwib@hotmail.com
md5mw@mdstud.chalmers.se

Downloads

Download source - 110 Kb


Comments

  • DataCombo Control

    Posted by kedochanh on 04/04/2005 05:20am

    How I use Binding DataCombo? And DBCombo , when Add these from activeX Control

    Reply
  • SameParent

    Posted by trusty on 05/06/2004 09:50am

    Great work. Thank for making it available for free. I have a question about the SameBranchAndLevel mode. In the test program, if you use Ctrl-A in this mode, you will select only the brothers of the current selection, in the same branch. But with CTRL pressed, you can select also the children of the other branches of the same level. Is it normal ? or a mode SameParent is missing ?

    Reply
  • Is makefile available?

    Posted by Legacy on 10/03/2003 12:00am

    Originally posted by: Lynn Allan

    Thanks for providing this sourcecode. I was wondering if you have (or could "make") a makefile. I'd like to be able to use the sdk.

    TIA,
    Lynn Allan

    Reply
  • Great Treeview - 1 suggestion...

    Posted by Legacy on 06/19/2003 12:00am

    Originally posted by: Jason

    I have been using your treeview control for a couple of weeks now, and its great! Im not sure how Microsoft could release a control like this without including some type of "multi-select" option - MAJOR oversight.

    One thing Ive noticed that is behaving slightly different than expected is the right click event. When I right click on a node, BEFORE I left click on it, the node is not added to the MWTreeView.SelNodes collection. It has caused (is still causing) a few problems for me. Do you know a way around this? Is this the expected behavior, and if so, can I change it?

    Other than that, Its outstanding! Great work. You've saved me hours of development time.

    Jason


    Reply
  • MWTreeView

    Posted by Legacy on 05/06/2003 12:00am

    Originally posted by: David P

    Nice work, though I have some nitpicks...
    
    - Tree items get selected when you release the mouse button
    rather than when you click it, giving a less responsive
    impression.
    - "Label edit" seems non-functional.
    - No focus rectangle unless MultiSelect is set to NoMulti.

    Reply
  • Are my MWControls working well?

    Posted by Legacy on 05/01/2003 12:00am

    Originally posted by: Mikael Wiberg

    Nobody has posted anything, so I take it my MWControls are working well?
    Has anyone found them useful? If so which one(s)?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 7, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT This eSeminar will explore three popular games engines and how they empower developers to create exciting, graphically rich, and high-performance games for Android® on Intel® Architecture. Join us for a deep dive as experts describe the features, tools, and common challenges using Marmalade, App Game Kit, and Havok game engines, as well as a discussion of the pros and cons of each engine and how they fit into your development …

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds