由3个标签组成

直接代码

    public partial class Roof : UserControl
{
public Roof()
{
InitializeComponent();
} private string text = "";//中间文字
private float valueL = 0.00f;//默认值0.00
private float valueR = 0.00f;
private bool _isChecked = false;//是否选中
private int roofId = ; /// <summary>
/// RoofId可用于作为唯一标识
/// </summary>
[Description("RoofId可用于作为唯一标识"), Category("自定义")]
public int RoofId
{
get
{
return this.roofId;
}
set
{
this.roofId = value;
}
}
/// <summary>
/// 显示内容
/// </summary>
[Description("显示内容"), Category("自定义")]
public string ShowText
{
get
{
return this.text;
}
set
{
this.text = value;
lbl_TxT.Text = value;
}
} /// <summary>
/// 左边值
/// </summary>
[Description("左边值"), Category("自定义")]
public float ValueL
{
get
{
return this.valueL;
}
set
{
this.valueL = value;
lbl_L.Text = value.ToString();
}
} /// <summary>
/// 右边值
/// </summary>
[Description("右边值"), Category("自定义")]
public float ValueR
{
get
{
return this.valueR;
}
set
{
this.valueR = value;
lbl_R.Text = value.ToString();
}
} /// <summary>
/// 是否选中
/// </summary>
[Description("是否选中"), Category("自定义")]
public bool IsChecked
{
get
{
return this._isChecked;
}
set
{
this._isChecked = value; if (value) { lbl_TxT.BorderStyle = BorderStyle.FixedSingle; } else { lbl_TxT.BorderStyle = BorderStyle.None; } }
} private void lbl_TxT_Click(object sender, EventArgs e)
{
if (_isChecked)
{
lbl_TxT.BorderStyle = BorderStyle.None;
_isChecked = false;
}
else
{ lbl_TxT.BorderStyle = BorderStyle.FixedSingle;
_isChecked = true;
} } #region 定位各个控件位置 private void roof_SizeChanged(object sender, EventArgs e)
{ AutoPosition(); } private void AutoPosition()
{
var roofHeight = this.Height;
var roofWidth = this.Width;
lbl_L.Width = roofWidth / ;
lbl_R.Width = roofWidth / ;
lbl_TxT.Width = roofWidth / ;
lbl_L.Height = roofHeight - ;
lbl_R.Height = roofHeight - ;
lbl_TxT.Height = roofHeight - ; //lbl_TxT.BackColor = Color.BlueViolet;
//lbl_R.BackColor = Color.Red;
//lbl_L.BackColor = Color.Blue; this.lbl_L.Location = new System.Drawing.Point(, roofHeight / - lbl_L.Height / );
this.lbl_R.Location = new System.Drawing.Point(roofWidth - lbl_R.Width, roofHeight / - lbl_R.Height / );
this.lbl_TxT.Location = new System.Drawing.Point(roofWidth / , roofHeight / - lbl_TxT.Height / );
} #endregion /// <summary>
/// 控件加载出来
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void roof_Load(object sender, EventArgs e)
{
lbl_R.Text = valueR.ToString();
lbl_L.Text = valueL.ToString();
//默认背景颜色
this.BackColor = System.Drawing.Color.FromArgb(, , );
AutoPosition();
}
}

Roof.cs

    partial class Roof
{
/// <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 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lbl_L = new System.Windows.Forms.Label();
this.lbl_R = new System.Windows.Forms.Label();
this.lbl_TxT = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lbl_L
//
this.lbl_L.BackColor = System.Drawing.Color.Transparent;
this.lbl_L.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.25F);
this.lbl_L.Location = new System.Drawing.Point(, );
this.lbl_L.Name = "lbl_L";
this.lbl_L.Size = new System.Drawing.Size(, );
this.lbl_L.TabIndex = ;
this.lbl_L.Text = "50.00";
this.lbl_L.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lbl_L.Click += new System.EventHandler(this.lbl_TxT_Click);
//
// lbl_R
//
this.lbl_R.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.25F);
this.lbl_R.Location = new System.Drawing.Point(, );
this.lbl_R.Name = "lbl_R";
this.lbl_R.Size = new System.Drawing.Size(, );
this.lbl_R.TabIndex = ;
this.lbl_R.Text = "51.00";
this.lbl_R.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lbl_R.Click += new System.EventHandler(this.lbl_TxT_Click);
//
// lbl_TxT
//
this.lbl_TxT.BackColor = System.Drawing.Color.Transparent;
this.lbl_TxT.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.25F);
this.lbl_TxT.Location = new System.Drawing.Point(, );
this.lbl_TxT.Name = "lbl_TxT";
this.lbl_TxT.Size = new System.Drawing.Size(, );
this.lbl_TxT.TabIndex = ;
this.lbl_TxT.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lbl_TxT.Click += new System.EventHandler(this.lbl_TxT_Click); //
// roof
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.lbl_TxT);
this.Controls.Add(this.lbl_R);
this.Controls.Add(this.lbl_L);
this.Name = "roof";
this.Size = new System.Drawing.Size(, );
this.Load += new System.EventHandler(this.roof_Load);
this.SizeChanged += new System.EventHandler(this.roof_SizeChanged);
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Label lbl_L; private System.Windows.Forms.Label lbl_R;
private System.Windows.Forms.Label lbl_TxT;
}

roof.Designer.cs

效果图

WinForm 自定义控件 - RooF的更多相关文章

  1. C# winform 自定义控件

    近来因为项目的问题,开始研究winform自定义控件,这篇主要是将自定义控件的属性在属性编辑器中可编辑,如果你对自定义控件比较了解的,就不用继续往下看了 首先,我创建了一个类UserButton,继承 ...

  2. C#winform自定义控件模拟设计时界面鼠标移动和调节大小、选中效果

    要想玩转Winform自定义控件需要对GDI+非常熟悉,对常用的控件有一些了解,好选择合适的基类控件来简化. 要点说明及代码 1)定义接口: using System; using System.Wi ...

  3. Winform自定义控件实例

    本文转自http://www.cnblogs.com/hahacjh/archive/2010/04/29/1724125.html 写在前面: .Net已经成为许多软件公司的选择,而.Net自定义W ...

  4. winform 自定义控件:半透明Loading控件

    winform  自定义控件:半透明Loading控件 by wgscd date:2015-05-05 效果: using System;using System.Drawing;using Sys ...

  5. c#Winform自定义控件-目录

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  6. (二)c#Winform自定义控件-按钮

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  7. (三)c#Winform自定义控件-有图标的按钮

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  8. (四)c#Winform自定义控件-选择按钮组

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  9. (七)c#Winform自定义控件-进度条

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

随机推荐

  1. RHEL7.2 SSH无密码登录非root用户

    1 修改三台虚拟机的/ect/hosts文件 [hadoop@hadoop01 ~]$ cat /etc/hosts 127.0.0.1 localhost localhost.localdomain ...

  2. web前端开发面试题(Vue.js)

    1.active-class是哪个组件的属性?嵌套路由怎么定义? 答:vue-router模块的router-link组件. 2.怎么定义vue-router的动态路由?怎么获取传过来的动态参数?  ...

  3. pycharm的安装流程

    以windows版本举例: 1.首先去Pycharm官网,或者直接输入网址:http://www.jetbrains.com/pycharm/download/#section=windows,下载P ...

  4. tensorflow学习笔记——模型持久化的原理,将CKPT转为pb文件,使用pb模型预测

    由题目就可以看出,本节内容分为三部分,第一部分就是如何将训练好的模型持久化,并学习模型持久化的原理,第二部分就是如何将CKPT转化为pb文件,第三部分就是如何使用pb模型进行预测. 一,模型持久化 为 ...

  5. git 删除误上传的.idea文件

    问题: 提交项目的时候忘记添加.gitignore文件,误上传了文件(如.idea)如何解决?(本文以.idea文件夹举例) 1.将项目文件拉取下来 git pull origin master 2. ...

  6. windows下的nginx应用

    nginx(背景) nginx是一个高性能的HTTP服务器,以前我经常在linux系统中配置,主要做反向代理和负载均衡,最近根据业务需要,需要在window中配置反向和负载,下面就介绍一下nginx的 ...

  7. 4sql

    在 MySQL 中,有三种主要的类型:文本.数字和日期/时间类型. Text 类型:CHAR(size)VARCHAR(size)TINYTEXTTEXT 存放最大长度为 65,535 个字符的字符串 ...

  8. Java语法进阶10-多线程

    多线程 并发与并行.进程,线程调度自行百度 线程(thread):是一个进程中的其中一条执行路径,CPU调度的最基本调度的单位.同一个进程中线程可以共享一些内存(堆.方法区),每一个线程又有自己的独立 ...

  9. sql注入问题回顾

    (以下语法均为在python中使用mysql语句,部分代码省略,使用python中的pymsql模块获取游标对象即可直接执行sql语句) sql注入:在传入参数的时候做出改变,使得插入数据这条sql语 ...

  10. kafka官方的kafka-server-start.sh不能关闭kafka进程解决办法

    vi kafka-server-stop.sh 把PIDS=$(ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{pr ...