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 aStripSplitButton
(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:
- Include SplitButton.cs and SplitButton.designer.cs in your project.
- Load the assembly in the toolbox of Visual Studio, or just insert a
Button
control in your form, and then change the type fromButton
toSplitButton
.[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:
- Add an
ImageList
to your form (or control or whatever) and set theImageList
property of theSplitButton
to thisImageList
. - Add images you want to the
ImageList
for theSplitButton
splitter side statuses:Normal
,Hover
,Clicked
,Disabled
,Focused
. - 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 theImageList
of theSplitButton
). - Now, you can set some suggested options:
TextAlign
toMiddleLeft
,ImageAlign
toMiddleRight
, andTextImageRelation
toTextBeforeImage
. 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 theSplitButton
.bool AlwaysDropDown
- Indicates whether theSplitButton
always shows the drop down menu even if the button part is clicked.bool AlwaysHoverChange
- Indicates whether theSplitButton
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 ifCalculateSplitRect
is set totrue
).int SplitWidth
- The split width (ignored ifCalculateSplitRect
is set totrue
).
In addition to this, there are two events:
ButtonClick
- Occurs when the button part of theSplitButton
is clicked.ButtonDoubleClick
- Occurs when the button part of theSplitButton
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!
0 Comments:
Đăng nhận xét