Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / Visual Basic
Article

Improved and Recoded RibbonMenuButton

Rate me:
Please Sign up or sign in to vote.
4.93/5 (160 votes)
5 Jun 2007CPOL4 min read 355.4K   14.8K   493   86
A new version with many functionalities
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Expediteapps
Spain Spain
I'm Electronic Engineer, I did my end degree project at Astrophysical Institute and Tech Institute. I'm HP Procurve AIS and ASE ,Microsoft 3.5 MCTS
I live in Canary Islands ,developing customized solutions

Deeply involved in Xamarin Forms LOB (including Azure Cloud with offline support, custom controls, dependencies) projects, WP8.1 & W10 projects, WPF modern styled projects. Portable libraries like portablePDF, portableOneDrive, portableReports and portablePrinting (using Google Printing API).


Web and apps showcase at:
Expediteapps


Take a look to my blog
Blog

Comments and Discussions

 
Questionneed vb.net 3.5 version Pin
Masood1234516-Dec-12 22:03
Masood1234516-Dec-12 22:03 
GeneralMy vote of 5 Pin
Kanasz Robert27-Sep-12 8:35
professionalKanasz Robert27-Sep-12 8:35 
GeneralRe: My vote of 5 Pin
Juan Pablo G.C.2-Oct-12 0:37
Juan Pablo G.C.2-Oct-12 0:37 
SuggestionBUGS FIX (when Radius less than 2 and TextAlign not work) Pin
xitour7-May-12 20:57
xitour7-May-12 20:57 
GeneralRe: BUGS FIX (when Radius less than 2 and TextAlign not work) Pin
Juan Pablo G.C.8-May-12 21:31
Juan Pablo G.C.8-May-12 21:31 
GeneralMy vote of 5 Pin
Eduardo_David5-Jun-11 3:05
Eduardo_David5-Jun-11 3:05 
GeneralMy vote of 5 Pin
noreply-thephoenixprod11-May-11 20:36
noreply-thephoenixprod11-May-11 20:36 
GeneralMy vote of 5 Pin
Anirudha_Gohokar28-Jan-11 2:43
Anirudha_Gohokar28-Jan-11 2:43 
GeneralDownload - Refactored w/ Lot's of Bug fixes and Performance Improvments Pin
Tom Guinther26-Nov-10 6:25
Tom Guinther26-Nov-10 6:25 
GeneralRibbon button Pin
Viktor_6915-Nov-10 3:02
Viktor_6915-Nov-10 3:02 
GeneralMy vote of 5 Pin
Viktor_6915-Nov-10 3:00
Viktor_6915-Nov-10 3:00 
GeneralMy vote of 5 Pin
Global Analyser3-Nov-10 10:12
Global Analyser3-Nov-10 10:12 
GeneralBrilliant :) Pin
Anthony Daly10-Sep-10 12:39
Anthony Daly10-Sep-10 12:39 
GeneralMy vote of 5 Pin
Member 32887887-Aug-10 8:42
Member 32887887-Aug-10 8:42 
GeneralMy vote of 5 Pin
pebeeye28-Jul-10 17:23
pebeeye28-Jul-10 17:23 
GeneralText Aligned Don't work Pin
sepel5-Apr-09 21:50
sepel5-Apr-09 21:50 
GeneralExtremely Awesome Work Pin
Xmen Real 9-Mar-09 23:54
professional Xmen Real 9-Mar-09 23:54 
QuestionWhat about licence then Pin
BastianPL23-Jan-09 3:28
BastianPL23-Jan-09 3:28 
QuestionGreat! And how about glowing one? Pin
Manuel Quelhas23-Dec-08 23:36
Manuel Quelhas23-Dec-08 23:36 
GeneralColors, ForeColor Pin
Infinity99922-Dec-08 2:37
Infinity99922-Dec-08 2:37 
GeneralThank you so much for your amazing posts - I have few questions Pin
Wael Salman19-Dec-08 1:35
Wael Salman19-Dec-08 1:35 
GeneralSome properties did not work :( [modified] Pin
Dzung T.N8-Aug-08 20:49
Dzung T.N8-Aug-08 20:49 
GeneralRe: Fix the bugs Pin
xitour7-May-12 20:52
xitour7-May-12 20:52 
GeneralTab key press Pin
piyush74198205-May-08 20:21
piyush74198205-May-08 20:21 
Generalstrip menu does not work by me Pin
trupik27-Feb-08 20:14
trupik27-Feb-08 20:14 

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

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