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

Improved and Recoded RibbonMenuButton

By Juan Pablo G.C.

A new version with many functionalities
C# 2.0, VB 8.0, C#, VB, Windows, .NET, .NET 2.0VS2005, Visual Studio, Dev, Design

Posted: 14 May 2007
Updated: 5 Jun 2007
Views: 111,992
Bookmarked: 276 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
120 votes for this Article.
Popularity: 9.90 Rating: 4.76 out of 5
3 votes, 2.5%
1
1 vote, 0.8%
2
2 votes, 1.7%
3
6 votes, 5.0%
4
108 votes, 90.0%
5
Screenshot - presentation.png

Introduction

First of all, thanks to everyone. I am grateful to know that people value this effort. I remember like yesterday when I was sixteen, more or less, and I saw many types of software, apps and games. For me, it was impossible to access and develop software then. I have learned a lot since, however, and I realize that it's now one million times easier to access this kind of software. Furthermore, if I can help anyone to create eye-candy apps, I've decided that they can use my code freely.

Background

I was thinking about how to make a fully customizable button and about how difficult it was changing RGB components. I decided to make RibbonColor, which has many options to operate with colors. If you play the demo app, you will understand quickly as you move the Hue, Sat and Brightness track bar. I have to admit that I have approximately 70% of the new RibbonControl library finished. However, as people are anxious to have improved code and have told me that I did not explain practically anything about my code, I've decided to do this like for dummies. So, here we go.

How to Use the Code

First of all, create a new Windows application. From the Solution Explorer, choose the option Add Existing Item. Then choose RibbonMenuButton.cs and Rebuild the project. Now, if you go to the form1 designer, in the toolbox you will have RibbonMenuButton. Drag it to the form. You will see a control without sense, but let's play with the properties. First, set properties for the RibbonMenuButton:

Screenshot - ribbonmenubuttonprops.png

When you have set the properties, add an image, set the text you want and set the font to Segoe UI if you have it. You will have something like this:

Screenshot - trialbutton.png

If you have compiled the project and you get this, the next step is to change the properties of the control. Let's see what each property represents. I recommend that you look at the button's Properties settings in the demo project:

  • Arrow: Paints an arrow ToRight or ToDown; this only paints, as the double functionality is in another property.
  • Colors: I think this doesn't need explanation; I recommend you to use the PlayGround app to choose your colors.
  • FadingSpeed: This facilitates fading between colors; choose 0 to avoid fading.
  • GroupPos: This is to make round corners on the Left, Right, Center (None), Top or Bottom.
  • ImageLocation: To put the image on the Left, Right, Top or Bottom.
  • ImageOffset: To offset from the borders.
  • MaxImageSize: To make buttons larger with a scaling image limit.
  • Radius: The corner radius.
  • ShowBase: If you want to show the BaseColor and BaseStroke color where Transparent is a color and makes fading. If set to No, it doesn't make fading.
  • SplitButton: Creates a double function button; the arrow section opens the associated ContextMenu and the other section, the main event.
  • SplitDistance: How big the arrow section button is.
  • Title: If you set this different from "", it automatically puts the title bold and under the text.
  • Text: If you have a title and want two lines of text, add \n to the text to make two lines.
  • KeepPress, IsPressed: If KeepPress is active on some buttons, when one of them is pressed, it keeps the press and the others in the containers lose the IsPress.

I have tried to crash the app, but it always works. So, I think the code is effectively error-free.

Points of Interest

If you want to learn more about these controls, I recommend that you take a look at:

  • this.Region: That's a good way to avoid matters of transparency.
  • LinearGradient With multiple colors, that makes the gradients easy.
  • MeasureString: That's a good method to position the text because you have to take away the base.OnPaint -> you have to do everything, including write the text.
  • TransformColors Method including the alpha opacity.
  • DrawArc method: As you can see, with the radius you can make smooth corners.
  • OnMouseUp: Here you can see what happens when the SplitButton is activated and IsPressed activated.
  • RibbonColor: I took the formulas from Wikipedia and Gimp. The System.Drawing.Color.GetHue, Sat and Brightness don't work well.

History

  • 5 June, 2007. 1.6 - Solved Repaint, ChangingSize and excessive CPU consumption. Added KeepPress and IsPress functionality.
  • 16 May, 2007. 1.5 - Because I had to recode everything when I learned how to use Hue, Saturation and Brightness.

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

Juan Pablo G.C.


Mvp
I'm an Electronic Engineer, I did my end degree project at Astrophysical Institute and Tech Institute. I'm HP Procurve AIS and ASE helping at University, and I'm getting ready for Microsoft MCTS.
I live in Canary Islands. At the moment Im developing a CRM software for my company. I'm really interested know people getting the MCTS.
I'm an SQL Server and .net2.0 intermediate expert.

Take a look to my blog Juan Pablo G.C.
Overrider
Occupation: Web Developer
Location: Spain Spain

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 64 (Total in Forum: 64) (Refresh)FirstPrevNext
GeneralSome properties did not work :( [modified]memberTrung D21:49 8 Aug '08  
GeneralTab key pressmemberpiyush741982021:21 5 May '08  
Generalstrip menu does not work by memembertrupik21:14 27 Feb '08  
GeneralFound a bug on right clicking a button... [modified]memberOctopod6:50 10 Jan '08  
Generalso coolmemberJackChen198723:11 7 Jan '08  
GeneralI'm confusedmembertcsoccerman14:49 4 Dec '07  
GeneralAnother CPU bugmemberJordiproatec3:30 29 Nov '07  
General3 bug fixes (includin CPU issues)membergpgemini12:01 13 Oct '07  
GeneralTextAlign requests are ignoredmemberGrantM11:19 2 Oct '07  
GeneralHow to unable a RibbonMenuButton?memberivanchain@hotmail.com15:43 16 Sep '07  
GeneralHi, about the iconsmemberivanchain@hotmail.com4:44 11 Sep '07  
GeneralRe: Hi, about the iconsmemberAlpha Nerd8:32 24 May '08  
GeneralUsing this button as toolstripbuttonmemberVincent_ws18:09 10 Sep '07  
Generalmissing Ribbon MenumemberKamalmostofi12:40 31 Aug '07  
AnswerRe: missing Ribbon Menumemberqien23:32 15 Oct '07  
QuestionImage clippingmemberjoncle1238:50 12 Aug '07  
GeneralCPU problemsmemberRoey C12:05 4 Aug '07  
GeneralRe: CPU problemsmemberRoey C12:07 4 Aug '07  
QuestionIsPressed = true paint bug [modified]memberalleph10:51 26 Jul '07  
QuestionBug?memberjdem6:33 26 Jul '07  
Generalabout Office 2007 UI Licencememberalleph22:43 24 Jul '07  
AnswerRe: about Office 2007 UI LicencememberPraded4:26 5 Aug '07  
Generalmistake ,deadlinessmemberqingtianyu920:43 11 Jul '07  
Generalthe code..memberSeishin#6:00 19 Jun '07  
GeneralRe: the code.. [modified]memberMario M.6:15 16 Sep '07  

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

PermaLink | Privacy | Terms of Use
Last Updated: 5 Jun 2007
Editor: Genevieve Sovereign
Copyright 2007 by Juan Pablo G.C.
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project