You can create a custom style for each of the Measurement Studio numeric pointer .NET controls, including the knob, gauge, meter, slide, tank, and thermometer, by extending the style of the control. To create a custom style, you must derive from the style class associated with the control. For example, to extend the appearance of the knob control, you derive a class from the KnobStyle base class. Similarly, the other numeric pointer controls have a corresponding style class prefixed with the control name and suffixed with "Style." In the derived class, you must provide an implementation for DrawPointer. If you are creating a custom style for radial numeric pointer controls then you must also provide an implementation for DrawDial, and HitTest methods. If you are creating a custom style for linear numeric pointer controls then you must provide an implementation for DrawFillArea, and HitTest methods. Each control style may have additional abstract methods that require implementation. In general, you can delegate to an existing style for the implementation of the abstract method. Refer to the DrawDial method of the custom KnobStyle implementation in this topic for an example. Delegating to the existing style's implementation allows you to customize only the appearance of the part of the control that you are interested in.
This section details the implementation of a custom KnobStyle that draws the pointer away from the center of the dial of the control. Some of the radial numeric pointer styles override the default implementation of methods provided in the RadialNumericPointerStyle base class. If you derive a custom style from a radial numeric pointer style and implement its abstract methods by calling the methods on an existing style, you might also have to override some methods and call the existing style's implementation. You might have to override the following methods for the styles:
You know that you need to override these methods if the custom style that you create does not look exactly like the existing style that you are using to implement its abstract methods. For instance, the example below derives a custom style from KnobStyle and implements its abstract methods by calling the methods on RaisedWithThumb3D. If GetDialRadius is not overridden, you will notice that the dial covers much more area than in the RaisedWithThumb3D style. Overriding the GetDialRadius method and implementing it by calling the GetDialRadius method of the RaisedWithThumb3D property results in the custom style looking like the original style.
The attached code provides the implementation for the custom KnobStyle.
To use the custom knob style implementation with a knob, create an instance of the CustomKnobStyle class and assign it to the KnobStyle property. The following example assumes that a Knob named knob1 has been declared and initialized.
Knob1.PointerColor = Color.Gray
Knob1.KnobStyle = New CustomKnobStyle
knob1.PointerColor = Color.Gray;
knob1.KnobStyle = new CustomKnobStyle();
The following image shows the effect of using the custom style on a knob:
This section details the implementation of a custom SlideStyle that draws highlights over the scale on a slide. Some of the linear numeric pointer styles override the default GetScaleReferenceBounds implementation provided in the LinearNumericPointerStyle base class. If you derive a custom style from a linear numeric pointer style and implement its abstract methods by calling the methods on an existing style, you might also have to override the GetScaleReferenceBounds method and call the existing style's implementation. You know that you need to override the GetScaleReferenceBounds method if the custom style that you create does not look exactly like the existing style that you are using to implement its abstract methods. For instance, the example below derives a custom style from SlideStyle and implements its abstract methods by calling the methods on RaisedWithRoundedGrip3D. If GetScaleReferenceBounds is not overridden, you will notice that the size of the custom style appears larger than the RaisedWithRoundedGrip3D style. Overriding the GetScaleReferenceBounds method and implementing it by calling the GetScaleReferenceBounds method of the RaisedWithRoundedGrip3D property results in the custom style looking like the original style.
The attached code provides the implementation for the custom SlideStyle.
To use the custom slide style implementation with a slide, create an instance of the CustomSlideStyle class and assign it to the SlideStyle property. The following example assumes that a Slide called slide1 has been declared and initialized.
Slide1.SlideStyle = New CustomSlideStyle
slide1.SlideStyle = new CustomSlideStyle();
The following image shows the effect of using the custom style on a slide:
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.