# Run-time Interaction

Learn how to use different events that occur for C1Gauge and C1GaugeBase components as a result of various user actions at runtime. See more demos, documentation, and samples here.

## Content



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.

*   **ItemStateChanged** – fires when a hit-testable item becomes enabled, hot, pressed, or vice-versa.
*   **ItemClick** – fires when a gauge element is clicked.
*   **ItemDoubleClick** – fires when a gauge element is double-clicked.
*   **ItemMouseEnter** – fires when the mouse pointer enters a gauge element.
*   **ItemMouseLeave** – fires when the pointer leaves a gauge element.
*   **ItemMouseMove** – fires when the mouse pointer is moved over a gauge element.
*   **ItemMouseDown** – fires when the pointer is over a gauge element and a mouse button is pressed.
*   **ItemMouseUp** – fires when the mouse pointer is over a gauge element and a mouse button is released.

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:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
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
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

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

DOC-DETAILS-TAG-CLOSE

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

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
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
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

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

DOC-DETAILS-TAG-CLOSE

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.

*   **C1GaugeBase.PointerDragBegin** – fires when a user starts dragging a gauge pointer.
*   **C1GaugeBase.PointerDragEnd** – fires when the user ends dragging a gauge pointer.
*   **C1GaugeBase.PointerDragMove** – fires when a gauge element is dragged with the mouse.
*   **C1GaugeBase.PointerDragCancel** – allows resetting the pointer value to its original state.

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

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
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
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
private void c1RadialGauge1_PointerDragMove(object sender, PointerDragEventArgs e)
{
e.Pointer.UpdateValue(e.NewValue, 0.25);
}
```

DOC-DETAILS-TAG-CLOSE

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

[Shadows](/componentone/docs/win/online-gauges/workingwithgaugesfor/shadows)