C# LED显示控件(原创)

本人个人主页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 partial class FlyingWindToolsExample : Form
    {
        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;
        }

    }
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值