Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#
Article

The new RibbonForm, RibbonRoundButton, and FastMenu

Rate me:
Please Sign up or sign in to vote.
4.41/5 (59 votes)
3 Jun 2007CPOL2 min read 150.8K   5.2K   157   76
A free version of RibbonForm, RibbonRoundButton, and RibbonFastMenu.

Screenshot - RibbonTest.png

Introduction

In this article, I present the RibbonForm, RibbonRoundButton, and RibbonFastMenu as a release version. I present RibbonContextMenu as a preview version because I have to improve some parameters to work with it well.

The Controls

RibbonForm 1.0

Screenshot - RibbonForm.png

The RibbonForm was a bit difficult to design due to it being a modeless window, and I had to implement all the resizing and window moving by myself. Also, I had to implement a HSB method to change colors.

Properties

The RibbonForm has these properties:

  • CompB: To change the Brightness of the Form with a value that I recommend to get from the RibbonFormSample (see screenshot above).
  • CompS: To change the Saturation of the Form, the same as above.
  • CompH: To change the Hue of the Form, the same as above.
  • TextSection: It's the subtitle of the Form with the harmony color.

How to use

In a new Windows application, add an existing item from the Solution Explorer, and choose the RibbonForm.cs (it adds the other files needed). Now, in the Form1.cs code, change to this:

C#
using RibbonStyle; //To add the NameSpace

namespace RibbonTest
{
    public partial class Form1 : RibbonForm //To inherit from RibbonForm
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
} 

RibbonRoundButton 1.0

Screenshot - RibbonRound.png

It was really hard to design a vectorial round button with fading, but I think it finished well.

Properties

The RibbonRoundButton has these properties:

  • ColorBase, ColorOn, ColorPress: The typical colors.
  • ColorStroke: Is the border of the button.
  • ImgOffset: You can move the image from topleft to rightdown.
  • ImgScale: You can scale the image from 1 to 100.

How to use

You can choose two options: as other buttons, you can add the DLL in Class_RibbonRoundButton, or you can add an existing item in the Solution Explorer and choose RibbonRoundButton.cs, then recompile and add the button to the Form.

RibbonFastMenu 1.0

It's the form that appears when you click on the MenuButton on the top-left. This Form has the typical app options.

I have to implement a SetHSB() method to change the colors, but it is functional.

How to use

In a Windows application, choose Add Existing Item, and select the RibbonFastMenu.cs. I recommend adding all the existing resources from the RibbonTest app to have all the images, and then you will have a Form like in the first image of the article.

Comments

I'm designing a better way to use the RibbonContextMenu because I think it's a bit difficult to use, but please be patient till I finish it.

Keep in mind

  • I have to add the SetHSB() method to the FastMenu.
  • Make a better way to implement the FastMenu.
  • Make a stable version of the RibbonContextMenu.

History

  • June 2007 - RibbonForm 1.0, RibbonFastMenu 1.0, RibbonRoundButton 1.0.

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

 
QuestionI get error Severity Code "The name 'InitializeComponent' does not exist in the current context " Pin
DavisMillier12-Nov-16 4:25
DavisMillier12-Nov-16 4:25 
GeneralMy vote of 2 Pin
i0024-Jun-14 1:47
i0024-Jun-14 1:47 
GeneralRe: My vote of 2 Pin
Juan Pablo G.C.11-Jul-14 3:42
Juan Pablo G.C.11-Jul-14 3:42 
SuggestionForm Resize/Positioning Fix (modification) Pin
Someguydude30-Jun-12 5:59
Someguydude30-Jun-12 5:59 
GeneralTidy up the code == Fix CPU utilisation Pin
seeblunt1-Sep-09 13:53
seeblunt1-Sep-09 13:53 
GeneralCPU 100% Pin
naami_siq22-Nov-08 23:00
naami_siq22-Nov-08 23:00 
GeneralRe: CPU 100% Pin
kapil bhavsar26-Jun-09 1:37
kapil bhavsar26-Jun-09 1:37 
GeneralCPU 100% Pin
naami_siq22-Nov-08 22:57
naami_siq22-Nov-08 22:57 
GeneralA suggestion to improve the form Pin
javar9-Sep-08 20:34
javar9-Sep-08 20:34 
GeneralFew problems in your implementation Pin
HawVie15-Apr-08 0:06
HawVie15-Apr-08 0:06 
GeneralRe: Few problems in your implementation Pin
Mark Rice11-Aug-08 8:26
Mark Rice11-Aug-08 8:26 
GeneralGenerating code for alt colour Pin
Derek Bartram29-Jan-08 20:20
Derek Bartram29-Jan-08 20:20 
GeneralComments Pin
derek_bartram29-Jan-08 13:52
derek_bartram29-Jan-08 13:52 
GeneralFormBorder style Pin
Crusty Applesniffer2-Jan-08 5:51
Crusty Applesniffer2-Jan-08 5:51 
GeneralBug in RibbonColor [modified] Pin
The_Mega_ZZTer17-Aug-07 8:19
The_Mega_ZZTer17-Aug-07 8:19 
public uint AC { get { return ac; } set { System.Math.Min(value, 255); } }


I think this is supposed to be

public uint AC { get { return ac; } set { ac = System.Math.Min(value, 255); } }


Also click-and-drag window moving is a bit wonky (it only works while the mouse is over the titlebar, and since your form is a bit slow at moving and redrawing you have to move the mouse real slooooow or else the window stops moving.

[Edit: I fixed this second problem. Wasn't too hard since it's only a page or two of code. I had converted it to VB.NET for my own project so the replacement code I cobbled together is also VB.NET, but it shouldn't be too hard to modify the original C# using it as a template.

What this code does is it only checks where the mouse cursor is on mouse down, instead of every mouse move, to determine whether it should size or move the window. The result is behavior closer to Windows' default.

#Region "Mouse Events"
        Private Function SelectFormBorderAction() As formborderactions
            Dim p As Point = PointToClient(Control.MousePosition)
            If p.Y > Me.Height - cornerssize Then
                'Bottom Right
                If p.X > Me.Width - cornerssize Then
                    Return formborderactions.size_se
                ElseIf p.X < cornerssize Then
                    'Bottom Left

                    Return formborderactions.size_sw
                Else
                    'Bottom
                    Return formborderactions.size_s
                End If
            End If

            If p.Y < cornerssize Then
                'Top Right
                If p.X > Me.Width - cornerssize Then
                    Return formborderactions.size_ne
                ElseIf p.X < cornerssize Then
                    'Top Left

                    Return formborderactions.size_nw
                ElseIf p.Y < 3 And p.X > cornerssize And p.X < Me.Width - cornerssize Then
                    'Top
                    Return formborderactions.size_n
                Else
                    Return formborderactions.moving
                End If
            ElseIf p.X < cornerssize Then
                Return formborderactions.size_w
            ElseIf p.X > Me.Width - cornerssize Then
                Return formborderactions.size_e
            End If
            Return formborderactions.none
        End Function

        Private _mousedown As Boolean = False
        Private p_mouseoffset As Point
        Protected Overloads Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
            _mousedown = True
            p_mouseoffset = PointToClient(Control.MousePosition)
            formborderaction = SelectFormBorderAction()

            Me.Refresh()
            MyBase.OnMouseDown(e)
        End Sub

        Protected Overloads Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
            _mousedown = False

            formborderaction = formborderactions.none
            Me.Refresh()
            MyBase.OnMouseUp(e)
        End Sub

        Private Enum formborderactions As Integer
            none
            moving
            size_nw
            size_n
            size_ne
            size_w
            size_e
            size_sw
            size_s
            size_se
        End Enum
        Private formborderaction As formborderactions = formborderactions.none

        Private cornerssize As Integer = 30
        Private _mouseposonwindow As Point
        Protected Overloads Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
            _mouseposonwindow = PointToClient(Control.MousePosition)

            If Not _mousedown Then
                Select Case SelectFormBorderAction()
                    Case formborderactions.moving, formborderactions.none
                        Cursor = Cursors.Arrow
                    Case formborderactions.size_e, formborderactions.size_w
                        Cursor = Cursors.SizeWE
                    Case formborderactions.size_n, formborderactions.size_s
                        Cursor = Cursors.SizeNS
                    Case formborderactions.size_ne, formborderactions.size_sw
                        Cursor = Cursors.SizeNESW
                    Case formborderactions.size_nw, formborderactions.size_se
                        Cursor = Cursors.SizeNWSE
                End Select
            Else
                Select Case formborderaction
                    Case formborderactions.moving
                        Dim mouseposonscreen As Point = Control.MousePosition
                        mouseposonscreen.X = mouseposonscreen.X - p_mouseoffset.X
                        mouseposonscreen.Y = mouseposonscreen.Y - p_mouseoffset.Y
                        Me.Location = mouseposonscreen
                    Case formborderactions.size_e
                        Me.Size = New Size(_mouseposonwindow.X, Me.Height)
                    Case formborderactions.size_n
                        Me.Location = New Point(Me.Location.X, Me.Location.Y + e.Y)
                        Me.Size = New Size(Me.Width, Me.Height - e.Y)
                    Case formborderactions.size_ne
                        Me.Location = New Point(Me.Location.X, Me.Location.Y + e.Y)
                        Me.Size = New Size(_mouseposonwindow.X, Me.Height - e.Y)
                    Case formborderactions.size_nw
                        Me.Location = New Point(Me.Location.X + e.X, Me.Location.Y + e.Y)
                        Me.Size = New Size(Me.Width - e.X, Me.Height - e.Y)
                    Case formborderactions.size_s
                        Me.Size = New Size(Me.Width, _mouseposonwindow.Y)
                    Case formborderactions.size_se
                        Me.Size = New Size(_mouseposonwindow.X, _mouseposonwindow.Y)
                    Case formborderactions.size_sw
                        Me.Location = New Point(Me.Location.X + _mouseposonwindow.X, Me.Location.Y)
                        Me.Size = New Size(Me.Width - e.X, _mouseposonwindow.Y)
                    Case formborderactions.size_w
                        Me.Location = New Point(Me.Location.X + e.X, Me.Location.Y)
                        Me.Size = New Size(Me.Width - e.X, Me.Height)
                End Select
            End If
        End Sub

#End Region


[Edit: RibbonMenuButton.cs is not included in the RibbonFastMenu class zip. That code won't compile without it. Fortunately it's included in the sample. In addition RibbonFastMenu.cs seems to contain code from the Sample, meaning more files from the sample are needed to get it to build, including resources.]


-- modified at 17:32 Friday 17th August, 2007
GeneralRe: Bug in RibbonColor Pin
flash.tato27-Dec-07 4:48
flash.tato27-Dec-07 4:48 
General100% cpu power Pin
Roey C4-Aug-07 7:19
Roey C4-Aug-07 7:19 
Questionhow would you do this with other components Pin
MartyK20073-Aug-07 3:00
MartyK20073-Aug-07 3:00 
NewsGreat job! But I have s small question: Pin
Le.Wang1-Aug-07 3:01
Le.Wang1-Aug-07 3:01 
GeneralGREAT JOB! Pin
Sniper16720-Jul-07 10:33
Sniper16720-Jul-07 10:33 
GeneralRe: GREAT JOB! Pin
Juan Pablo G.C.21-Jul-07 22:54
Juan Pablo G.C.21-Jul-07 22:54 
QuestionIs it just me or is this unusable right now? Pin
eeMarcoK28-Jun-07 21:18
eeMarcoK28-Jun-07 21:18 
GeneralProblem in Resize with 2 monitors... Pin
PakT25-Jun-07 6:08
PakT25-Jun-07 6:08 
GeneralThanks! Pin
hoana200714-Jun-07 0:42
hoana200714-Jun-07 0:42 
GeneralDisposing of graphics objects Pin
razzielx7-Jun-07 9:41
razzielx7-Jun-07 9:41 

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.