Skip to main content Skip to footer

Adding Gauges to C1Ribbon

ComponentOne Ribbon has a RibbonControlHost element which can add arbitrary controls to Ribbon. You can easily add a control by defining a new class inheriting C1.Win.C1Ribbon.RibbonControlHost. First, we will discuss using the same RibbonControlHost element to host C1Gauge in the C1Ribbon and C1StatusBar controls.

Create Ribbon Application

Create a new Winforms application. Add a C1RibbonForm in the application and place C1Ribbon and C1StatusBar control. For more information, see Creating a Ribbon Application Project.

Designing GaugeHostControl Class

In the GaugeHostControl class we will create a gauge object by loading an existing template xml file in the C1LinearGauge object. We will also handle the PointerDragMove event to handle the pointer dragging in the control. The class is as follows:

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);  
    }  

}

After adding this class, build the application.

Adding GaugeHostControl in C1Ribbon & C1StatusBar

After the application is built, open the RibbonForm. The following are the simple steps that add GaugeHostControl in C1Ribbon.

  1. Click Group1 of C1Ribbon and from the floating toolbar click the Action button and select Add ControlHost. The AddingRibbonControlHost dialog box will open.
  2. Type the name of the control host in the Adding RibbonControlHost dialog box. For example, "ProjectName.FormName+TextBoxHost" replaces ProjectName and FormName with the names or your project and form. In our case we will add "GaugeInC1RibbonDemo.GaugeHostControl."
  3. Click OK to close the Adding RibbonControlHost dialog box.

Repeat the same steps with C1StatusBar to add the GaugesHostControl. At run time you will be able to interact with the C1Gauge element as you would a standard TextBox. Download Sample

MESCIUS inc.

comments powered by Disqus