ComponentOne Ribbon for WinForms
Embedding a Gauge in a Ribbon Group
C1Ribbon (Classic) Task-Based Help > Embedding Controls in a Ribbon > Embedding a Gauge in a Ribbon Group

You can host a C1Gauge control in a C1RibbonGroup or in a C1StatusBar control through using the RibbonControlHost element. Complete the following steps to embed a C1Gauge in a C1RibbonGroup:

Note: This help uses a template file to create the ruler view for the C1Gauge control. To create this file, add a C1Gauge control to a Windows Form and choose the Linear Gauge Simple Ruler template from the New Gauge Gallery dialog box. Open the C1Gauge smart tag and click Save to XML File. Enter the file name Ruler.xml and click Save.

  1. Create a new Ribbon application. (For more information see Creating a Ribbon Application Project)
  2. Add a C1Ribbon control and a C1StatusBar control to the form. Change the Windows Form to a Ribbon Form by modifying the code that declares your form.
  3. Right-click the Windows Form and select View Code.
  4. Replace the class declaration with the following code to change the Windows Form to aRibbon Form:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Partial Class Form1
    Inherits C1.Win.C1Ribbon.C1RibbonForm
    End Class
    

    To write code in C#

    C#
    Copy Code
    public partial class Form1 : C1RibbonForm
    
  5. While still in code view, we will add a C1Gauge control by defining a new class using the RibbonControlHost. This code will also handle the PointerDragMove event to handle the pointer dragging in the control. Add the following code to the top of the page:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Imports C1.Win.C1Gauge
    Imports System.Xml
    

    To write code in C#

    C#
    Copy Code
    using C1.Win.C1Gauge;
    using System.Xml;
    
  6. Add the following code after the InitializeComponent() method:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Public Class GaugeHostControl
         Inherits C1.Win.C1Ribbon.RibbonControlHost
               Private linearGauge As C1LinearGauge
              Public Sub New()
             MyBase.New(New C1.Win.C1Gauge.C1Gauge)
             linearGauge = New C1LinearGauge
             Dim doc As XmlDocument = New XmlDocument
             doc.LoadXml(Properties.Resources.Ruler)
             linearGauge.Load(doc)
             C1Gauge.Gauges.Add(linearGauge)
             C1Gauge.BackColor = System.Drawing.Color.Azure
             linearGauge.PointerDragMove = (linearGauge.PointerDragMove + LinearGauge_PointerDragMove)
         End Sub
              <Browsable(false),  _
                                    DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _  
                            Public ReadOnly Property C1Gauge As C1.Win.C1Gauge.C1Gauge
             Get
                 Return CType(Control,C1.Win.C1Gauge.C1Gauge)
             End Get
         End Property
        
         Private Sub LinearGauge_PointerDragMove(ByVal sender As Object, ByVal e As PointerDragEventArgs)
             e.Pointer.UpdateValue(e.NewValue, 0.5)
         End Sub
     End Class
    

    To write code in C#

    C#
    Copy Code
    public class GaugeHostControl : C1.Win.C1Ribbon.RibbonControlHost 
    { 
        private C1LinearGauge linearGauge; 
        public GaugeHostControl() : base(new C1.Win.C1Gauge.C1Gauge()) 
        { 
            linearGauge = new C1LinearGauge(); 
            XmlDocument doc = new XmlDocument(); 
            doc.LoadXml(Properties.Resources.Ruler); 
            linearGauge.Load(doc); 
            C1Gauge.Gauges.Add(linearGauge); 
            C1Gauge.BackColor = System.Drawing.Color.Azure; 
            linearGauge.PointerDragMove += LinearGauge_PointerDragMove; 
        } 
        [Browsable(false)]    
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]   
        public C1.Win.C1Gauge.C1Gauge C1Gauge 
        { 
            get 
            { 
                return (C1.Win.C1Gauge.C1Gauge)Control; 
            } 
        } 
        private void LinearGauge_PointerDragMove(System.Object sender, PointerDragEventArgs e) 
        { 
            e.Pointer.UpdateValue(e.NewValue, 0.5); 
        } 
    }
    
  7. From the Solution Explorer, open the Resources.resx file. Click Add Resource | Add Existing File and choose the Ruler.xml file from the folder in which it was saved.
  8. Build your project before switching back to Design View. Open theRibbon Group Floating Toolbar by selecting the empty Ribbon Group.
  9. Click the Actions button and select Add Control Host from the list. The Adding RibbonControlHost dialog window will appear.
  10. Enter a class name for the RibbonControlHost to be added. The class name should follow the ProjectName.FormName+GaugeHostControl format, substituting the names of your project and form for ProjectName and FormName as in the following image:
  11. Run your application. The C1Ribbon application should appear as follows: