Advanced reporting
and data visualization components for .NET
LIVE CHAT Welcome, guest

What is the difference between the Widget and IndicatorWidget components?

Widget and IndicatorWidget are used to display and edit gauges in Windows Forms applications. The Widget component is intended for displaying and controlling instrument with the help of the mouse. The IndicatorWidget component is a descendant from the Widget. It is designed to provide immediate access to the Slider element and more convenient edit options of this element in a particular case when only one slider is used in the instrument. Indicator Widget provides additional capabilities for access to the Value property and the ValueChanged event of the indicated slider.

Let’s see in practice what the difference between these two components is and what their advantages are.

Description of the Widget Component.

Run Visual Studio; create Windows Forms application with one form. Then place the Widget component, which can be found in the Visual Studio Toolbox, on the form.

running designer from VS.NET

The Instrument designer is launched by double click on the component or from its contextual menu. In the invoked designer, open the existing element with the help of the SharpShooter Gauges Wizard. For example, open Double Dial1 from the Dials folder. Confirm the changes by clicking the “OK” button. The selected element will be displayed in the Widget component.

Run the application to check up instrument availability.

The received gauge is displayed in the Widget component. It reacts upon the user actions.
Now we need to realize the ability to receive and set the current control element value. To do it, let’s use the widget1.Instrument property which returns the instrument object. In order to get to the desired element, for example, to the Slider1 or the Slider2, use the GetObject function of the instrument.

Then put the Label components onto the form for displaying the gauge element values in text form. Add the following lines to the program code. Here, the Form1_Load is the Load event handler of the program main form.

private Slider slider1 = null;

private Slider slider2 = null;

private void Form1_Load(object sender, System.EventArgs e)
{
slider1 = widget1.Instrument.GetObject("Slider1") as Slider;
slider2 = widget1.Instrument.GetObject("Slider2") as Slider;
slider1.ValueChanged += new PerpetuumSoft.Framework.Model.PropertyEventHandler(slider1_ValueChanged);
slider2.ValueChanged += new PerpetuumSoft.Framework.Model.PropertyEventHandler(slider2_ValueChanged);
}

private void slider1_ValueChanged(object sender, PerpetuumSoft.Framework.Model.PropertyEventArgs args)
{
label1.Text = "Slider1.Value = " + slider1.Value.ToString("0.00");
}

private void slider2_ValueChanged(object sender, PerpetuumSoft.Framework.Model.PropertyEventArgs args)
{
label2.Text = "Slider2.Value = " + slider2.Value.ToString("0.00");
}

Program work result.

To get the instrument element which is placed at the assigned point you can use the GetElementAt method. You can realize the MouseMove event handler in the following way:

private void widget1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
PerpetuumSoft.Instrumentation.Model.Element element = widget1.GetElementAt(e.X, e.Y);
label3.Text = "Mouse is over " + element.Name;
}

Program work result.

You can review the received result in the WidgetUseExample.

The Widget component has the following specific properties:
1. ZoomScale – assigns the instrument scale coefficient;
2. HideFocusRectangle – indicates whether the rectangle around the control should be drawn, when it is in a focus.
3. InvalidateInterval – if this value is more than zero, the timer for renewing the area occupied by the instrument will be used.

InvalidateInterval assigns the renewal period in milliseconds.

Description of the IndicatorWidget Component.

The IndicatorWidget component use is similar to the Widget component.
But the IndicatorWidget features properties which allow simple receiving of the current value of one of the gauge sliders. The Value property and the ValueChanged event are added to the IndicatorWidget. They correspond to the Value property and ValueChanged event of one of the instrument sliders used in the IndicatorWidget. In order to assign the exploitable slider, its name is assigned in the SliderName property.

Besides, the IndicatorWidget allows moving a specified slider automatically by means of the keyboard. The shift step is assigned in the Increment property.

It is possible to change values range for the selected slider scale using the Minimum and Maximum properties. Please, pay special attention to the fact that all above-listed properties have no meaning until the instrument or the desired instrument slider’ name for the IndicatorWidget is assigned. If the instrument is assigned, it is more convenient to assign the name of the used slider in the SliderName property pulldown. The names of all instrument sliders are displayed in the list.

Let’s consider the IndicatorWidget use by the example. Run Visual Studio; create Windows Forms application with one form. Put the IndicatorWidget component on the form.

The instrument designer is invoked by the double click on the component or from its contextual menu. In the invoked designer, open the existing instrument with the help of the SharpShooter Gauges Wizard. For example, open Dial4 from the Dials folder. Confirm the changes by clicking the “OK” button. The selected instrument is displayed in the IndicatorWidget component.

Run the application to check the instrument availability.

Put the Label component on the form to display current value of control elements as text. In order to have access to the slider value, assign the SliderName property in Slider1. Realize the ValueChanged event handler in the following way:

private void indicatorWidget1_ValueChanged(object sender, PerpetuumSoft.Framework.Model.PropertyEventArgs args)
{
label1.Text = "Current Value = " + indicatorWidget1.Value.ToString("0.00");
}

Program work result.

The access to the current slider value is simplified (compare with the similar example of the Widget component use). So, if you need to access current slider value of the gauge slider, it is preferable to use the IndicatorWidget. Now change the scale range within which the slider is moving with the help of the Minimum and Maximum properties. Set the Maximum value to 100.

For the convenience of changing slider value from the key board, set the Increment property val