bright, fresh software
Downloads  |  Buy

SplitButton control, written in C#

Re: SplitButton control, written in C#

Postby kerrywano » August 28th, 2007, 10:39 am

I'm glad I found your post. I was looking for some cool new (free, of course) components to kind of spice up a new internal application. I could be using this to replace quite a few comboboxes.

Personally, I'm a VBer, but I can read much of C#. I know it isn't of any particular consequence, but I have converted the latest version to VB.NET 2.0 for anyone interested.

Thanks,
kerrywano
 
Posts: 1
Joined: August 28th, 2007, 10:32 am

Re: SplitButton control, written in C#

Postby Wyatt » August 31st, 2007, 5:13 am

kerrywano wrote:I'm glad I found your post. I was looking for some cool new (free, of course) components to kind of spice up a new internal application. I could be using this to replace quite a few comboboxes.

Personally, I'm a VBer, but I can read much of C#. I know it isn't of any particular consequence, but I have converted the latest version to VB.NET 2.0 for anyone interested.

Thanks,


Sure, e-mail it to me and I'll add it to the first post.

-Wyatt
User avatar
Wyatt
Site Admin
 
Posts: 3097
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: SplitButton control, written in C#

Postby Aaron » September 19th, 2007, 2:10 am

Hi,

The FlatStyle "Flat" does not work for this SplitButton. Do you have an idea how i can accomplish that?

Thanks,
Aaron
Aaron
 

Re: SplitButton control, written in C#

Postby Wyatt » September 19th, 2007, 8:06 pm

Aaron wrote:Hi,

The FlatStyle "Flat" does not work for this SplitButton. Do you have an idea how i can accomplish that?

Thanks,
Aaron


The flat style is not a theme-inherited style - that is, it doesn't look like the themed buttons in Vista & XP. This means it will not change from one version of Windows to another. So, to accomplish the 'Flat' look is actually a rather simple task.

Just open up the project in Visual Studio (or whichever development environment you use) and edit the 'OnPaint(PaintEventArgs pevent)' method in the SplitButton.cs file. Then it's just a matter of replacing the existing code with a switch statement for each of the button's states:

Code: Select all
switch(State)
{
   case PushButtonState.Default:
      //TODO: insert painting code
   break;
   case PushButtonState.Disabled:
      //TODO: insert painting code
   break;
   case PushButtonState.Hot:
      //TODO: insert painting code
   break;
   case PushButtonState.Normal:
      //TODO: insert painting code
   break;
   case PushButtonState.Pressed:
      //TODO: insert painting code
   break;
}


Then where each comment is, replace it with drawing code that draws the rectangle background and the 1px/2px black frame for that particular button state.

The reason I didn't (and won't) implement the alternate FlatStyles is because they look amateur.

However, if you're developing for a client with those particular stylistic needs, then who am I to impose my own standards?
User avatar
Wyatt
Site Admin
 
Posts: 3097
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: SplitButton control, written in C#

Postby JoeRip » October 17th, 2007, 10:27 pm

What I'd like is a simple dropdown that allows me to have a different width for the control than for the dropdown list. Since I can't find a forms-friendly control that does that (ie, not a toolstrip bound control), I use your split button, even though I don't need the split itself.

So, given this - is there any way I can get the drop down list to drop if the user clicks anywhere in the button, as opposed to just the right side? I want it to function exactly as if they had right clicked, essentially.
JoeRip
 

Re: SplitButton control, written in C#

Postby Wyatt » October 18th, 2007, 10:14 am

JoeRip wrote:What I'd like is a simple dropdown that allows me to have a different width for the control than for the dropdown list. Since I can't find a forms-friendly control that does that (ie, not a toolstrip bound control), I use your split button, even though I don't need the split itself.

So, given this - is there any way I can get the drop down list to drop if the user clicks anywhere in the button, as opposed to just the right side? I want it to function exactly as if they had right clicked, essentially.


Well, you'll have to change a few methods. For example, the OnKeyDown method will have to be changed to

Code: Select all
        protected override void OnKeyDown(KeyEventArgs kevent)
        {
            if (showSplit)
            {
                if (kevent.KeyCode.Equals(Keys.Down) || kevent.KeyCode.Equals(Keys.Space))
                {
                    ShowContextMenuStrip();
                }
            }

            base.OnKeyDown(kevent);
        }


and make similar changes to OnKeyUp. Though, the main thing you'll need to change is to OnMouseDown:

Code: Select all
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!showSplit)
            {
                base.OnMouseDown(e);
                return;
            }

            //always show the context menu, no matter where clicked
            ShowContextMenuStrip();
        }


And obviously you'll want to change the drawing code to never draw the "split" line. There will be other subtleties that you'll need to work out to get it working perfectly, but that should get you started.

If you need more help, feel free to ask.
User avatar
Wyatt
Site Admin
 
Posts: 3097
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: SplitButton control, written in C#

Postby mc_ginley » December 6th, 2007, 4:46 pm

Hey you,
just wanted to say a big thank you. Your control is EXACTLY what i was looking for!!! Really good work. Thanks a lot.
regards
jOe
mc_ginley
 

Re: SplitButton control, written in C#

Postby Guy » February 7th, 2008, 11:23 am

First thing's first: this is so far the best SplitButton implementation I've come across. Thanks!

Now, on to the whining! :)

If I set an image on the SplitButton, and have nothing set for the "SplitMenu" property, then the image is drawn on the button and everything is right in the world. But as soon as I set the SplitMenu property, the button is redrawn without the image. This happens on all the "TextImageRelation" enums I've tried. I assume it's gotta be happening in the OnPaint override, but I'm having trouble tracking it down. Any ideas good sir?

Thanks!
Guy
 

Re: SplitButton control, written in C#

Postby Wyatt » February 7th, 2008, 2:28 pm

Guy wrote:First thing's first: this is so far the best SplitButton implementation I've come across. Thanks!


I'm glad this control is so popular.

Guy wrote:Now, on to the whining! :)

If I set an image on the SplitButton, and have nothing set for the "SplitMenu" property, then the image is drawn on the button and everything is right in the world. But as soon as I set the SplitMenu property, the button is redrawn without the image.


That's because I didn't implement the image painting in the code. I'll have a fixed version listed on the first post (and a blog post) tomorrow night.

Edit, Feb. 8, 2008: The new version (1.6) has image support. Tell me if you find any bugs.
User avatar
Wyatt
Site Admin
 
Posts: 3097
Joined: July 11th, 2007, 10:30 pm
Location: New Hampshire

Re: SplitButton control, written in C#

Postby Guy » February 12th, 2008, 9:20 am

Thanks Wyatt! :)
Guy
 

PreviousNext

Return to Open Source Support