Click here to Skip to main content
Licence CPOL
First Posted 18 Sep 2006
Views 187,972
Bookmarked 160 times

SplitButton: an XP style dropdown split button

By | 25 Oct 2006 | Article
The SplitButton control represents a dropdown split button in standard theme-supported XP style.

Demo

Demo

Introduction

Yesterday, I was thinking the best way to solve a particular situation (specific actions derived logically from one) was a split button. Searching and searching on MSDN produced no results, so I was perplexed: no split button in .NET? No, there isn't. The strange thing is that a StripSplitButton (or something like that) exists, that is, the split button equivalent for the ToolStrip. Probably, not being a standard control for the system, they though not to include the control, because it was easy to simulate its functionality with images, and that's what I did.

Using the code

The control is very easy to use. Anyway, this is the step-by-step how-to-do:

  1. Include SplitButton.cs and SplitButton.designer.cs in your project.
  2. Load the assembly in the toolbox of Visual Studio, or just insert a Button control in your form, and then change the type from Button to SplitButton.

    [Updated: Oct '06] You can stop here, default images for split states will be used by the control, or you can follow next steps to customize split images.

    Optional:

  3. Add an ImageList to your form (or control or whatever) and set the ImageList property of the SplitButton to this ImageList.
  4. Add images you want to the ImageList for the SplitButton splitter side statuses: Normal, Hover, Clicked, Disabled, Focused.
  5. Now, have a look at the property windows for the SplitButton, go to "Split Button Images" category, and simply select an image for each status from the list box of images (the ones in the ImageList of the SplitButton).
  6. Now, you can set some suggested options: TextAlign to MiddleLeft, ImageAlign to MiddleRight, and TextImageRelation to TextBeforeImage. You're done.

Now you can set some custom options for the SplitButton, a brief description follows:

  • bool DoubleClickedEnabled - Indicates whether the double click event is raised on the SplitButton.
  • bool AlwaysDropDown - Indicates whether the SplitButton always shows the drop down menu even if the button part is clicked.
  • bool AlwaysHoverChange - Indicates whether the SplitButton always shows the hover image status in the split part even if the button part is hovered.
  • bool CalculateSplitRect - Indicates whether the split rectangle must be calculated (based on the split image size).
  • bool FillSplitHeight - Indicates whether the split height must be filled to the button height even if the split image height is lower.
  • int SplitHeight - The split height (ignored if CalculateSplitRect is set to true).
  • int SplitWidth - The split width (ignored if CalculateSplitRect is set to true).

In addition to this, there are two events:

  • ButtonClick - Occurs when the button part of the SplitButton is clicked.
  • ButtonDoubleClick - Occurs when the button part of the SplitButton is double-clicked.

Conclusion

It's only a simple control, I know, but it could be useful in my opinion.

So, that's all, I think. I hope you'll find it useful, bye!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Elia Sarti


Synved Ltd.
Ireland Ireland

Member





Synved : Logos / Designs / Websites / Development / FREE Quote / www.synved.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questioncontrol doesn't dispose created Image objects PinmemberPovilasPanavas1:21 18 Apr '12  
GeneralMy vote of 5 PinmemberMember 396389914:43 14 Jan '12  
QuestionAbout that arrow glyph... [modified] PinmemberT800G12:05 25 Dec '10  
AnswerRe: About that arrow glyph... PinmemberElia Sarti3:24 28 Dec '10  
GeneralMy vote of 5 Pinmemberversion2_13:42 28 Aug '10  
GeneralFound a bug Pinmemberkeegean2:45 23 Feb '10  
GeneralGreak Work PinmemberHui99819:54 27 Dec '09  
QuestionHow should i do to get this dropdown fuction to the web style dropdownlist 's effect? Pinmembertanglbin19:06 18 Nov '09  
GeneralGreat work. PinmemberNate Shoffner15:44 23 Jul '09  
GeneralThank you ! PinmemberJackChen198715:51 19 Jul '07  
GeneralRe: Thank you ! Pinmemberdubbele onzin8:52 9 Nov '07  
QuestionEvent to handle a subitem being clicked? PinmemberCdnProgrammer4:08 19 Jul '07  
AnswerRe: Event to handle a subitem being clicked? PinmemberGladstone5:31 19 Jul '07  
NewsSlightly more professional SplitButton [modified] PinmemberVB Guy15:43 24 Jun '07  
GeneralRe: Slightly more professional SplitButton PinmemberGladstone3:53 25 Jun '07  
GeneralRe: Slightly more professional SplitButton PinmemberVB Guy4:37 25 Jun '07  
GeneralRe: Slightly more professional SplitButton PinmemberGladstone6:38 25 Jun '07  
GeneralRe: Slightly more professional SplitButton PinmemberCdnProgrammer11:37 18 Jul '07  
I tried using the second one (that fixes Microsoft guy's errors), and received an error when I clicked on a button that had no items in it... not sure what happened there, but I'm going back to Microsoft guy's control until it works properly. Smile | :) Thanks for providing links to both.
GeneralPrevent right-click context menu PinmemberAutoDeveloper3:49 31 Oct '06  
GeneralRe: Prevent right-click context menu [modified] PinmemberGladstone6:26 31 Oct '06  
GeneralBackground image stays enabled Pinmembergolan.barnov4:44 21 Oct '06  
GeneralRe: Background image stays enabled PinmemberGladstone5:17 21 Oct '06  
GeneralRe: Background image stays enabled Pinmembergolan.barnov5:38 21 Oct '06  
GeneralRe: Background image stays enabled PinmemberGladstone13:57 21 Oct '06  
GeneralRe: Background image stays enabled PinmemberGladstone14:07 21 Oct '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 25 Oct 2006
Article Copyright 2006 by Elia Sarti
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid