Widget Component Use and Capabilities (Win Forms)

Let’s consider the use of the Widget component by the example.

Download the Sample Application: WidgetWinForms.zip

Create a Windows Forms application with one form. Then place the Widget component, which can be found on the SharpShooter Gauges tab in the Toolbox, on the form.

The Instrument designer is launched by mouse double click on the component. In the invoked designer, let’s open the existing element with the help of the SharpShooter Gauges Wizard. For example, open LightBlueGauge from the Gauge folder. Confirm the changes clicking the “OK” button. The selected element will be displayed in the Widget component.

Run the application for the instrument availability check-up.

The received control element is displayed in the Widget component. It reacts upon the user actions. Now the ability for receiving and setting the current control element value is needed. 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, let’s use the GetObject function of the instrument. Then put the Label components onto the form for displaying the control element value in text form.

Add the following lines in 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 in 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, MouseEventArgs e)
   {
    PerpetuumSoft.Instrumentation.Model.Element element = 
widget1.GetElementAt(e.X, e.Y);
    label3.Text = "Mouse is over " + element.Name;
   }

Program work result:

The Widget component has the following specific properties:

ZoomScale – assigns the instrument scale coefficient;

HideFocusRectangle – indicates whether the rectangle around the control should be drawn, when it is in a focus.

InvalidateInterval – if this value is more than zero, the timer for renewal of the area, occupied by the instrument, will be used.

InvalidateInterval assigns the renewal period in milliseconds.

Add Feedback