由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. 在VMware通过挂载系统光盘搭建本地yum仓库

    1.首先需要有一个VMware虚拟机: 2.进去虚拟机(这里用Linux下deCentOS进行演示): 3.用root账号进行登录,否则在根目录下没有一些操作权限: 4.打开终端: 5,输入命令“cd ...

  2. Condition对象以及ArrayBlockingQueue阻塞队列的实现(使用Condition在队满时让生产者线程等待, 在队空时让消费者线程等待)

    Condition对象 一).Condition的定义 Condition对象:与锁关联,协调多线程间的复杂协作. 获取与锁绑定的Condition对象: Lock lock = new Reentr ...

  3. Hadoop简述

    Haddop是什么? Hadoop是一个由Apache基金会所开发的分布式系统基础架构 主要解决,海量数据的存储和海量数据的分析计算问题. Hadoop三大发行版本 Apache版本最原始(最基础)的 ...

  4. 【2018寒假集训 Day2】【动态规划】钱币兑换(exchange)(自己翻译的2333)

    钱币兑换(exchange) 问题描述: Dave偶然获得了未来几天的美元(dollars)与马克(marks)之间的兑换率.例如Dave开始有100marks,请编写个程序帮助Dave找出最好的买卖 ...

  5. 计蒜客T1846AC记

    查看原题: 原题地址 初步思路: 采用贪心法求解,贪心策略如下: 排序,优先买最便宜的. 累加总数ans 初步代码: (楼主评语:其实其他地方的编程实现不太重要,贪心策略才是问题) #include ...

  6. “达观杯”文本分类--baseline

    结合tfidf权重,对“达观杯”提供的文本,进行文本分类,作为baseline,后续改进均基于此. 1.比赛地址及数据来源 "达观杯"文本智能挑战赛 2.代码及解析 # -*- c ...

  7. NTP服务编译安装报错:/usr/bin/ld: cannot find –lcap

    [root@localhost local]# find / -name "*libcap.so*" [root@localhost ntp-4.2.8p13]# cd /usr/ ...

  8. 如何使用Selenium来计算自动化测试的投资回报率?

    跨浏览器测试是一种测试,需要大量的精力和时间.通过不同的浏览器,操作系统,设备,屏幕分辨率测试Web应用程序,以评估针对各种受众的Web内容呈现的过程是一项活动.特别是如果手动处理.使用Seleniu ...

  9. Linux下用Docker部署接口安全的运行环境

    背景:MySQL数据库运行在宿主机上(Linux) 需求:Redis.服务.页面分别运行在独立的docker中,并处于同一网络,容器内部重要目录要挂载在物理目录,保证数据安全 方法: 一.设置网络环境 ...

  10. vue实例化过程

    我们在用vue进行开发项目时,是否存在疑惑,new Vue(xxx)的过程中,究竟发生了什么?定义的数据,是如何绑定到视图上的?本篇主要介绍在实例化vue时,主要做了哪些事,文章比较长,主要篇幅内容为 ...