5,696,576 members and growing! (13,152 online)
Email Password   helpLost your password?
Desktop Development » Button Controls » General     Intermediate

SplitButton: an XP style dropdown split button

By Gladstone

The SplitButton control represents a dropdown split button in standard theme-supported XP style.
C#.NET 2.0, Win2K, WinXP, Windows, .NET, GDI+, Visual Studio, VS2005, Dev

Posted: 18 Sep 2006
Updated: 25 Oct 2006
Views: 88,754
Bookmarked: 99 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
19 votes for this Article.
Popularity: 5.51 Rating: 4.31 out of 5
2 votes, 10.5%
1
0 votes, 0.0%
2
2 votes, 10.5%
3
2 votes, 10.5%
4
13 votes, 68.4%
5

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Gladstone



Location: Italy Italy

Other popular Button Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 29 (Total in Forum: 29) (Refresh)FirstPrevNext
GeneralThank you !memberJackChen198716:51 19 Jul '07  
GeneralRe: Thank you !memberdubbele onzin9:52 9 Nov '07  
QuestionEvent to handle a subitem being clicked?memberCdnProgrammer5:08 19 Jul '07  
AnswerRe: Event to handle a subitem being clicked?memberGladstone6:31 19 Jul '07  
NewsSlightly more professional SplitButtonmemberVB Guy16:43 24 Jun '07  
GeneralRe: Slightly more professional SplitButtonmemberGladstone4:53 25 Jun '07  
GeneralRe: Slightly more professional SplitButtonmemberVB Guy5:37 25 Jun '07  
GeneralRe: Slightly more professional SplitButtonmemberGladstone7:38 25 Jun '07  
GeneralRe: Slightly more professional SplitButtonmemberCdnProgrammer12:37 18 Jul '07  
GeneralPrevent right-click context menumemberAutoDeveloper4:49 31 Oct '06  
GeneralRe: Prevent right-click context menu [modified]memberGladstone7:26 31 Oct '06  
GeneralBackground image stays enabledmembergolan.barnov5:44 21 Oct '06  
GeneralRe: Background image stays enabledmemberGladstone6:17 21 Oct '06  
GeneralRe: Background image stays enabledmembergolan.barnov6:38 21 Oct '06  
GeneralRe: Background image stays enabledmemberGladstone14:57 21 Oct '06  
GeneralRe: Background image stays enabledmemberGladstone15:07 21 Oct '06  
GeneralRe: Background image stays enabledmembergolan.barnov16:31 22 Oct '06  
GeneralA much easier way without programming.memberNice Life22:25 26 Sep '06  
GeneralRe: A much easier way without programming.memberleggan22:41 26 Sep '06  
GeneralRe: A much easier way without programming.memberNice Life23:03 26 Sep '06  
GeneralRe: A much easier way without programming.memberleggan23:13 26 Sep '06  
AnswerRe: A much easier way without programming.membertCodex9:29 14 Nov '06  
GeneralRe: A much easier way without programming.memberAdadurov11:16 24 Feb '08  
Generaldo u have a .net 1.1 source available ?memberpepedupuis5:10 25 Sep '06  
GeneralRe: do u have a .net 1.1 source available ?memberGladstone8:51 25 Sep '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 Oct 2006
Editor: Smitha Vijayan
Copyright 2006 by Gladstone
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project