ComponentOne Gauges for WinForms
Working with Gauges for WinForms / User Interaction / Run-time Interaction
In This Topic
    Run-time Interaction
    In This Topic

    There are a number of events that occur for C1Gauge and C1GaugeBase components as the result of various user actions at runtime. The source of these events is a hit-testable element that can be obtained from the Item property of the ItemEventArgs object passed to the event handlers.

    The ItemStateChanged event can be used for updating appearance of a gauge item when it becomes hot or pressed. After setting C1Gauge.SupportsTransitionEffect to True you can apply the special transition effect when changing the state of a gauge item. For example:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub c1LinearGauge1_ItemStateChanged(ByVal sender As System.Object, _
      ByVal e As ItemEventArgs) Handles c1LinearGauge1.ItemStateChanged
           If TypeOf e.Item Is C1GaugePointer Then
                  Dim p As C1GaugePointer = CType(e.Item, C1GaugePointer)
                  c1Gauge1.BeginUpdate()
                  
                  If e.ItemPressed Then
                         p.Filling.CommonFillingName = "pressedFilling"
                  ElseIf e.ItemHot Then
                         p.Filling.CommonFillingName = "hotFilling"
                  Else
                         p.Filling.CommonFillingName = "normalFilling"
                  End If
                  
                  c1Gauge1.EndUpdate(200)
           End If
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void c1LinearGauge1_ItemStateChanged(object sender, ItemEventArgs e)
    {
           if (e.Item is C1GaugePointer)
           {
                  C1GaugePointer p = e.Item as C1GaugePointer;
                  c1Gauge1.BeginUpdate();
                  
                  if (e.ItemPressed)
                         p.Filling.CommonFillingName = "pressedFilling";
                  else if (e.ItemHot)
                         p.Filling.CommonFillingName = "hotFilling";
                  else
                         p.Filling.CommonFillingName = "normalFilling";
                         
                  c1Gauge1.EndUpdate(200);
           }
    }
    

    The ItemMouseDown and ItemMouseMove events can be used for updating the pointer value. For example:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub c1RadialGauge1_ItemMouseDown(ByVal sender As System.Object, _
      ByVal e As ItemMouseEventArgs) Handles C1RadialGauge1.ItemMouseMove, C1RadialGauge1.ItemMouseDown
    If (e.Button And MouseButtons.Left) = MouseButtons.Left Then
     Dim p As C1GaugePointer = e.Gauge.Pointer
     p.Value = p.GetValueAt(e.X, e.Y)
    End If
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void c1RadialGauge1_ItemMouseDown(object sender, ItemMouseEventArgs e)
    {
     if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
      {
       C1GaugePointer p = e.Gauge.Pointer;
       p.Value = p.GetValueAt(e.X, e.Y);
      }
    }
    

    In the above sample we convert the mouse position to a value using the C1GaugePoiner.GetValueAt() function. It may be difficult for the user to specify any concrete value using this method. To facilitate it we can round the value to the nearest multiple of the given step (snapInterval) using the C1GaugePointer.UpdateValue() method instead setting a value to the C1GaugePointer.Value property directly. Then, the next line


    p.Value = p.GetValueAt(e.X, e.Y)

    should be replaced with something like the following:


    p.UpdateValue(p.GetValueAt(e.X, e.Y), 1.0)

    After that, the assigned value will be rounded automatically to integer numbers.

    There are a few additional events in the C1GaugeBase component. They allow interaction with gauge pointers.

    The C1GaugeBase.PointerDragMove event allows simple updating of the pointer value. For example:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub c1RadialGauge1_PointerDragMove(ByVal sender As System.Object, _
      ByVal e As PointerDragEventArgs) Handles c1RadialGauge1.PointerDragMove
    e.Pointer.UpdateValue(e.NewValue, 0.25)
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void c1RadialGauge1_PointerDragMove(object sender, PointerDragEventArgs e)
    {
    e.Pointer.UpdateValue(e.NewValue, 0.25);
    }
    

    The same handler can be attached to the C1GaugeBase.PointerDragCancel event. To use this event please make sure that the C1Gauge.Selectable property equals to True. If the user is dragging the pointer and decides to cancel this change and return to the previous value she can press the ESC key. Then, the PointerDragCancel event will be fired with the PointerDragEventArgs.NewValue property set to the previous value.

    It is now possible to use the keyboard events, such as Control.KeyDown, Control.KeyPress, and others, with the C1Gauge control after setting the C1Gauge.Selectable property to True. You can also attach a handler to the C1Gauge.DrawFocus event. This gives ability to change the bounds of the focus rectangle or draw your own focus selection.

    See Also