Académique Documents
Professionnel Documents
Culture Documents
Introduction
Seven and sixteen segment indicators are controls for Windows WPF applications. Each component is split by some figures (shapes)
with nearly the same form and size. Different combinations of colorized segments allow visualizing digital information such as
temperature, time, different calculations and other characters. There are lot of similar controls or ways to create similar labels for
.NET applications, but without full customization. I have tried to put together as many design configuration possibilities as possible
in a single component.
Background
Mostly, segment controls in this application derive from the one base UserControl named SegmentBase. From it derive such
controls as SevenSegments and SixteenSegments, which are responsible for displaying single character with segments.
There is additional base component SegmentsStackBase deriving from SegmentBase, it contains properties to display
sequence of segment controls. From this control come SevenSegmentsStack, which presents list of SevenSegments
components, and SixteenSegmentsStack, which presents list of SixteenSegments components.
Each segment has a corresponding number. Using these numbers, you can apply properties or make other actions with it. Segment
numbers are assigned according to the enumeration Segments.
https://www.codeproject.com/Articles/1277331/Seven-Segment-and-Sixteen-Segment-Controls-for-WPF?display=Print 1/6
14/02/2019 Seven-Segment and Sixteen-Segment Controls for WPF - CodeProject
Properties of Controls
Segment components have the following dependency properties to configure visual appearance:
Path geometries contain some geometric shapes, PathFigure. In turn, each PathFigure consists of lines and Bezier curves
connected with each other.
Points for each line and Bezier curve are calculated in separate functions.
https://www.codeproject.com/Articles/1277331/Seven-Segment-and-Sixteen-Segment-Controls-for-WPF?display=Print 3/6
14/02/2019 Seven-Segment and Sixteen-Segment Controls for WPF - CodeProject
Some of the shapes coordinates required additional calculation to draw inclination. Simple trigonometric equation has been used
according to an angle: tan(alpha) = a/b.
/// <summary>
/// Returns X-coord by the angle and height
/// </summary>
/// <param name="y">Y-coordinate to calculate height</param>
protected double XByAngle(double y)
{
var h = figureStartPointY - y;
return (TanAngle() * h);
}
/// <summary>
/// Returns tangent of the tilt angle in degrees
/// </summary>
protected double TanAngle()
{
return Math.Tan(TiltAngle * (Math.PI / 180.0));
}
Segments are marked as selected corresponding to the required value in the special function. You can extend this function to apply
not supported values.
For this moment, seven segment controls support only numeric values, sixteen segment controls support numeric values and capital
letters.
Also, there is a possibility to select segments without modifying control’s internal implementation through the use of dependency
property SelectedSegments.
int[] segments =
{
(int) SegmentsControls.Segments.LeftMiddle,
(int) SegmentsControls.Segments.RightBottomDiagonal
};
MySegments.ClearSegments();
MySegments.SelectedSegments = segments.ToList();
To apply different colors for particular segments outside control’s realization, it’s possible to use dependency property
SegmentsBrush.
https://www.codeproject.com/Articles/1277331/Seven-Segment-and-Sixteen-Segment-Controls-for-WPF?display=Print 4/6
14/02/2019 Seven-Segment and Sixteen-Segment Controls for WPF - CodeProject
MySegments.ClearSegments();
MySegments.SegmentsBrush = brushes.ToList();
<ItemsControl.ItemTemplate>
<DataTemplate>
<segm:ArrangedPanel >
<segm:SevenSegments Value="{Binding Item}"
ShowDot="{Binding ShowDot}"
OnDot="{Binding OnDot}"
Margin="5,0,0,0"/>
</segm:ArrangedPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
In order to apply dots or colons for these controls, it's required to set true for properties ShowDot or ShowColon and set
proper property Value (for example 1:23.4).
History
14th February, 2019 -- Original version posted
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile Article Copyright 2019 by Yury Yuhno
Web03 | 2.8.190210.1 | Last Updated 14 Feb 2019 Everything else Copyright © CodeProject, 1999-2019
https://www.codeproject.com/Articles/1277331/Seven-Segment-and-Sixteen-Segment-Controls-for-WPF?display=Print 6/6