Add project files.
This commit is contained in:
181
Owf.Controls.DigitalDisplayControl/DigitalDisplayControl.cs
Normal file
181
Owf.Controls.DigitalDisplayControl/DigitalDisplayControl.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Owf.Controls
|
||||
{
|
||||
public partial class DigitalDisplayControl : UserControl
|
||||
{
|
||||
private Color _digitColor = Color.GreenYellow;
|
||||
[Browsable(true), DefaultValue("Color.GreenYellow")]
|
||||
public Color DigitColor
|
||||
{
|
||||
get { return _digitColor; }
|
||||
set { _digitColor = value; Invalidate(); }
|
||||
}
|
||||
|
||||
private string _digitText = "88.88";
|
||||
[Browsable(true), DefaultValue("88.88")]
|
||||
public string DigitText
|
||||
{
|
||||
get { return _digitText; }
|
||||
set { _digitText = value; Invalidate(); }
|
||||
}
|
||||
|
||||
public DigitalDisplayControl()
|
||||
{
|
||||
this.SetStyle(ControlStyles.DoubleBuffer, true);
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
||||
InitializeComponent();
|
||||
this.BackColor = Color.Transparent;
|
||||
}
|
||||
|
||||
private void DigitalGauge_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
|
||||
SevenSegmentHelper sevenSegmentHelper = new SevenSegmentHelper(e.Graphics);
|
||||
|
||||
SizeF digitSizeF = sevenSegmentHelper.GetStringSize(_digitText, Font);
|
||||
float scaleFactor = Math.Min(ClientSize.Width / digitSizeF.Width, ClientSize.Height / digitSizeF.Height);
|
||||
Font font = new Font(Font.FontFamily, scaleFactor * Font.SizeInPoints);
|
||||
digitSizeF = sevenSegmentHelper.GetStringSize(_digitText, font);
|
||||
|
||||
using (SolidBrush brush = new SolidBrush(_digitColor))
|
||||
{
|
||||
using (SolidBrush lightBrush = new SolidBrush(Color.FromArgb(20, _digitColor)))
|
||||
{
|
||||
sevenSegmentHelper.DrawDigits(
|
||||
_digitText, font, brush, lightBrush,
|
||||
(ClientSize.Width - digitSizeF.Width) / 2,
|
||||
(ClientSize.Height - digitSizeF.Height) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SevenSegmentHelper
|
||||
{
|
||||
Graphics _graphics;
|
||||
|
||||
// Indicates what segments are illuminated for all 10 digits
|
||||
static byte[,] _segmentData = {{1, 1, 1, 0, 1, 1, 1},
|
||||
{0, 0, 1, 0, 0, 1, 0},
|
||||
{1, 0, 1, 1, 1, 0, 1},
|
||||
{1, 0, 1, 1, 0, 1, 1},
|
||||
{0, 1, 1, 1, 0, 1, 0},
|
||||
{1, 1, 0, 1, 0, 1, 1},
|
||||
{1, 1, 0, 1, 1, 1, 1},
|
||||
{1, 0, 1, 0, 0, 1, 0},
|
||||
{1, 1, 1, 1, 1, 1, 1},
|
||||
{1, 1, 1, 1, 0, 1, 1}};
|
||||
|
||||
// Points that define each of the seven segments
|
||||
readonly Point[][] _segmentPoints = new Point[7][];
|
||||
|
||||
public SevenSegmentHelper(Graphics graphics)
|
||||
{
|
||||
this._graphics = graphics;
|
||||
_segmentPoints[0] = new Point[] {new Point( 3, 2), new Point(39, 2), new Point(31, 10), new Point(11, 10)};
|
||||
_segmentPoints[1] = new Point[] {new Point( 2, 3), new Point(10, 11), new Point(10, 31), new Point( 2, 35)};
|
||||
_segmentPoints[2] = new Point[] {new Point(40, 3), new Point(40, 35), new Point(32, 31), new Point(32, 11)};
|
||||
_segmentPoints[3] = new Point[] {new Point( 3, 36), new Point(11, 32), new Point(31, 32), new Point(39, 36), new Point(31, 40), new Point(11, 40)};
|
||||
_segmentPoints[4] = new Point[] {new Point( 2, 37), new Point(10, 41), new Point(10, 61), new Point( 2, 69)};
|
||||
_segmentPoints[5] = new Point[] {new Point(40, 37), new Point(40, 69), new Point(32, 61), new Point(32, 41)};
|
||||
_segmentPoints[6] = new Point[] {new Point(11, 62), new Point(31, 62), new Point(39, 70), new Point( 3, 70)};
|
||||
}
|
||||
|
||||
public SizeF GetStringSize(string text, Font font)
|
||||
{
|
||||
SizeF sizef = new SizeF(0, _graphics.DpiX * font.SizeInPoints / 72);
|
||||
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
if (Char.IsDigit(text[i]))
|
||||
sizef.Width += 42 * _graphics.DpiX * font.SizeInPoints / 72 / 72;
|
||||
else if (text[i] == ':' || text[i] == '.')
|
||||
sizef.Width += 12 * _graphics.DpiX * font.SizeInPoints / 72 / 72;
|
||||
}
|
||||
return sizef;
|
||||
}
|
||||
|
||||
public void DrawDigits(string text, Font font, Brush brush, Brush brushLight, float x, float y)
|
||||
{
|
||||
for (int cnt = 0; cnt < text.Length; cnt++)
|
||||
{
|
||||
// For digits 0-9
|
||||
if (Char.IsDigit(text[cnt]))
|
||||
x = DrawDigit(text[cnt] - '0', font, brush, brushLight, x, y);
|
||||
// For colon :
|
||||
else if (text[cnt] == ':')
|
||||
x = DrawColon(font, brush, x, y);
|
||||
// For dot .
|
||||
else if (text[cnt] == '.')
|
||||
x = DrawDot(font, brush, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private float DrawDigit(int num, Font font, Brush brush, Brush brushLight, float x, float y)
|
||||
{
|
||||
for (int cnt = 0; cnt < _segmentPoints.Length; cnt++)
|
||||
{
|
||||
if (_segmentData[num, cnt] == 1)
|
||||
{
|
||||
FillPolygon(_segmentPoints[cnt], font, brush, x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillPolygon(_segmentPoints[cnt], font, brushLight, x, y);
|
||||
}
|
||||
}
|
||||
return x + 42 * _graphics.DpiX * font.SizeInPoints / 72 / 72;
|
||||
}
|
||||
|
||||
private float DrawDot(Font font, Brush brush, float x, float y)
|
||||
{
|
||||
Point[][] dotPoints = new Point[1][];
|
||||
|
||||
dotPoints[0] = new Point[] {new Point( 2, 64), new Point( 6, 61),
|
||||
new Point(10, 64), new Point( 6, 69)};
|
||||
|
||||
for (int cnt = 0; cnt < dotPoints.Length; cnt++)
|
||||
{
|
||||
FillPolygon(dotPoints[cnt], font, brush, x, y);
|
||||
}
|
||||
return x + 12 * _graphics.DpiX * font.SizeInPoints / 72 / 72;
|
||||
}
|
||||
|
||||
private float DrawColon(Font font, Brush brush, float x, float y)
|
||||
{
|
||||
Point[][] colonPoints = new Point[2][];
|
||||
|
||||
colonPoints[0] = new Point[] {new Point( 2, 21), new Point( 6, 17), new Point(10, 21), new Point( 6, 25)};
|
||||
colonPoints[1] = new Point[] {new Point( 2, 51), new Point( 6, 47), new Point(10, 51), new Point( 6, 55)};
|
||||
|
||||
for (int cnt = 0; cnt < colonPoints.Length; cnt++)
|
||||
{
|
||||
FillPolygon(colonPoints[cnt], font, brush, x, y);
|
||||
}
|
||||
return x + 12 * _graphics.DpiX * font.SizeInPoints / 72 / 72;
|
||||
}
|
||||
|
||||
private void FillPolygon(Point[] polygonPoints, Font font, Brush brush, float x, float y)
|
||||
{
|
||||
PointF[] polygonPointsF = new PointF[polygonPoints.Length];
|
||||
|
||||
for (int cnt = 0; cnt < polygonPoints.Length; cnt++)
|
||||
{
|
||||
polygonPointsF[cnt].X = x + polygonPoints[cnt].X * _graphics.DpiX * font.SizeInPoints / 72 / 72;
|
||||
polygonPointsF[cnt].Y = y + polygonPoints[cnt].Y * _graphics.DpiY * font.SizeInPoints / 72 / 72;
|
||||
}
|
||||
_graphics.FillPolygon(brush, polygonPointsF);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
Owf.Controls.DigitalDisplayControl/DigitalDisplayControl.designer.cs
generated
Normal file
47
Owf.Controls.DigitalDisplayControl/DigitalDisplayControl.designer.cs
generated
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace Owf.Controls
|
||||
{
|
||||
partial class DigitalDisplayControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// DigitalDisplayControl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.Color.Transparent;
|
||||
this.Name = "DigitalDisplayControl";
|
||||
this.Size = new System.Drawing.Size(150, 70);
|
||||
this.Paint += new System.Windows.Forms.PaintEventHandler(this.DigitalGauge_Paint);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
120
Owf.Controls.DigitalDisplayControl/DigitalDisplayControl.resx
Normal file
120
Owf.Controls.DigitalDisplayControl/DigitalDisplayControl.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{5D082F88-4290-4049-9984-FCB126A7BD4E}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Owf.Controls.DigitalDisplayControl</RootNamespace>
|
||||
<AssemblyName>Owf.Controls.DigitalDisplayControl</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>2.0</OldToolsVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DigitalDisplayControl.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DigitalDisplayControl.designer.cs">
|
||||
<DependentUpon>DigitalDisplayControl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="DigitalDisplayControl.resx">
|
||||
<DependentUpon>DigitalDisplayControl.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Owf.Controls.DigitalDisplayControl")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Owf.Controls.DigitalDisplayControl")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2007")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("464778c1-a779-407b-b4df-d2d61250c05c")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user