本人个人主页http://www.flyingwind.net/f/view.asp?id=227
C# LED显示控件(原创)是将一个32位int数据以二进制的形式显示,当相应位为1时灯亮,相应位为0时灯灭。
下图是将一个整数32456显示的结果。
LightIndicator类的属性
public int LightStatus{get, set}
灯的状态,改变此值 就可以显示不同结果。
public int NumLight{get, set}
灯的数目,取值范围为(1-32),例如当设置为3时,只显示三个灯即LightStatus的低三位数据
public Color LightOnColor {get, set}
灯打开(灯亮)时的颜色 ,此属性值应与LightOffCOlor不同否则将看不到效果。
public Color LightOffCOlor{get, set}
灯关闭(灯灭)时的颜色
public Color[] LightColors{get, set}
此属性允许你将不同的灯设置不同的颜色(此颜色是指灯亮时的颜色)
当此值不为NULL时LightOnColor 属性将失效,如果您显示灯的数目为10,但您设置LightColors数组长度为5,那么只有从右边往左数的前五个灯受此属性控制,其余的灯受LightOnColor控制。
此属性任何元素的值应与LightOffCOlor不同否则将看不到效果。
public string[] ToolTips{get, set}
此属性允许你为每个灯设置不同的ToolTip提示
数组中第n个元素的值对应第n个灯的ToolTip值,当数组的长度大于NumLight时后面的值会被忽略。
下载FlyingWindTools2011-08-11.zip
下载地址2(CSDN):http://download.csdn.net/source/3511433
范例
{
public FlyingWindToolsExample()
{
InitializeComponent();
numericUpDown1.Maximum = UInt32.MaxValue;
}
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.lightIndicator1 = new Net.FlyingWind.Tools.LightIndicator();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 41);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(125, 12);
this.label1.TabIndex = 2;
this.label1.Text = "LightIndicator显示值";
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(145, 37);
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(90, 21);
this.numericUpDown1.TabIndex = 3;
this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(247, 41);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(101, 12);
this.label2.TabIndex = 4;
this.label2.Text = "显示灯的数目1-32";
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(356, 37);
this.numericUpDown2.Maximum = new decimal(new int[] {
32,
0,
0,
0});
this.numericUpDown2.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(38, 21);
this.numericUpDown2.TabIndex = 5;
this.numericUpDown2.Value = new decimal(new int[] {
1,
0,
0,
0});
this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
//
// lightIndicator1
//
this.lightIndicator1.LightColors = null;
this.lightIndicator1.LightOffCOlor = System.Drawing.Color.Black;
this.lightIndicator1.LightOnColor = System.Drawing.Color.LimeGreen;
this.lightIndicator1.LightStatus = 0;
this.lightIndicator1.Location = new System.Drawing.Point(12, 12);
this.lightIndicator1.MinimumSize = new System.Drawing.Size(70, 12);
this.lightIndicator1.Name = "lightIndicator1";
this.lightIndicator1.NumLight = 32;
this.lightIndicator1.Size = new System.Drawing.Size(561, 12);
this.lightIndicator1.TabIndex = 0;
this.lightIndicator1.ToolTips = null;
//
// FlyingWindToolsExample
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(726, 380);
this.Controls.Add(this.numericUpDown2);
this.Controls.Add(this.label2);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.label1);
this.Controls.Add(this.lightIndicator1);
this.Name = "FlyingWindToolsExample";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Net.FlyingWind.Tools.LightIndicator lightIndicator1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
lightIndicator1.LightStatus = (int)numericUpDown1.Value;
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
lightIndicator1.NumLight = (int)numericUpDown2.Value;
}
}