Results 1 to 22 of 22

Thread: vs ToolBox-Type Control

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Location
    Portland, OR, USA
    Posts
    659

    vs ToolBox-Type Control

    GroupedTreeView Control and Accessories . . .

    OK. This is my first attempt at a custom control. I still consider myself a beginner, but I have to say, not too shabby for a first attempt.

    The Control uses version 3.5 of the .NET Framework, and the project file attachments are in vs2008. All Compiled elements have been removed.

    I have tried to re-create the basic look and functionality of the vs2008 Toolbox control, with reasonable success. The control inherits from TreeView, and can be used in much the same way as you would use a standard treeview control:

    1. The GroupedTreeView “Headers” are simply the Level 0 TreeNodes. When you populate this control, the first level of the node hierarchy is this.
    2. There is only one lower node level (Level 1). I did this on purpose, so that you get “headers” and “Items”.
    3. The GroupedTreeView.Imagelist is used to associate images/Icons with items at Level 1. Attempting to associate an image with a Level 0 node produces no change.
    4. The nodes for the control (Level 0 AND level 1) are entirely owner-drawn.
    5. There is a Class Called “GroupedTreeViewColorScheme” which defines pre-determined color schemes for the control. Due to the use of gradients, and the complexity of the TreeView Base Class, I decided it would be best this way. There are probably better ways to do it.

    Events and User interaction

    The Event handling for this was tricky, and I am hoping someone out there can find a better way to handle this. Apparently, the TreeNode Class responds differently depending on WHERE in the node area a mouseclick occurs. When Clicked over the area that hosts the +/– Symbol, the node expands/collapses, but does not select. When clicked in the area which hosts the Node Text, the node is selected, and expands/Collapses. When a click occurs in the area to the right of the node bounds (Where selection will occur if the FullRowSelect property is set to True), the node registers a double MousenodeClick Event, followed by double toggling of the control. In this case, the end result is no change in the expanded/collapsed status of the node (presumable to make room for the Fullrow select property, allowing users of TreeView to select a node from anywhere in this region without (visible) toggling).

    Unfortunately, I am after a control which models the behavior of the vs Toolbox, which reponds to a click ANYWHERE in the header area by selecting the header (if not selected), and toggling the Header Node. I achieved this, but at a price. There is now a sporadic flicker when one clicks on a selected Header node (most notable during the collapse operation). Not enough to junk the control, but it is annoying.

    I have not found a solution for this, and I have tried MANY different combinations of events and such. I suspect one probably needs to explore handling Windows messages at this point. If anyone has any ideas, or can improve on this, I would LOVE to see what you come up with!

    Drawing the Headers

    I did NOT get all of the detail found in the vs Toolbox Header into this version of the control. It looks pretty good, but this began as an effort to learn my way through control construction. Also, I wanted one of these for my App!!

    I don’t know if I have explained any of this well enough, or if I have tried to explain too much. This is my first codebank posting. I am also going to post it in “Code it better” forum, because I am calling this a finished effort for now, but would LOVE to hear where I could improve, and what could be done better.

    I have attached a vs Project file, and a folder with some images in it. The project file contains three classes and a simple WinForm to demo the control. The Project file has all necessary images set in My.Resources, but I included the stand-alone images for folks to work with.

    I have also attached another vs project file which is the same, except this one is set up as a Class Library project. Since I removed all the compiled elements from the file (The bin and obj folders, per jmcilhinney’s suggestion), you can build the class library version, and play with the control by adding it to your toolbox.

    Again, would love feedback, criticisms, comments, and most of all, pointers on how I SHOULD do it!

    I will follow this post with the code, which may take several more posts in a row.

    Thanks everyone!
    Attached Files Attached Files
    Last edited by RunsWithScissors; Sep 18th, 2009 at 09:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width