由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. C语言I博客作业09

    问题 答案 这个作业的属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/SE2019-4/homework/10034 我 ...

  2. opencv 1 HighGUI图形用户界面初步

    1图像载入 显示和输出到文件 Opencv的命名空间 Mat类 图像的载入:imread()函数 图片的显示:imshow()函数 创建窗口:namedWindow()函数 输出图像到文件:imwri ...

  3. python中的__str__和__repr__方法

    如果要把一个类的实例变成 str,就需要实现特殊方法__str__(): class A(object): def __init__(self,name,age): self.name=name se ...

  4. FIddler+Proxifer工具对windows PC客户端进行抓包

    python的大火,带动了python爬虫. 爬虫就必定绕不开抓包. 目前最常见的就是网页抓包了,可以使用chrome进行,或者配合其他抓包软件 fiddler. 小程序有些兴起是,如跳一跳之类的,也 ...

  5. linux/CentOS的安装(萌新版)

    一.CentOS的下载 1.官网下载网址:https://www.centos.org/ 2.下载具体步骤(2019年9月): 1.浏览器输入官方网址 2.点击网页的橙色按钮进入到下一界面 3.此时会 ...

  6. FPGA基础(verilog语言)——语法篇(续1)

    上一篇文章提到了FPGA中一个模块基本结构,这篇文章开始介绍语法. 首先,我们学习一门语言都要从这门语言的单词学起,所以verilog中的关键词都有哪些呢?看下面: A:always.assign B ...

  7. UCloud 云服务内容审核 Java 版本实现

    前言 最近不少小伙伴反映上传小黄图偶尔性的异常,并且不能上传动态图片,很是苦恼!无她,鉴黄API还没有这么智能,毕竟是自己训练的,不是那么专业!为了更好的服务广大网友,撸主决定接入更加智能快速的鉴黄服 ...

  8. Java包package之间调用问题-cmd运行窗口编译运行

    问题:在使用了java包机制(package)后,编译出现错误:找不到或无法加载主类 xxx 的错误提示信息(各种编译不通过) 先给演示结果: 编译:javac -d classes src/a/He ...

  9. 老男孩python 自学day09 函数开始

    什么是函数? 函数用关键字def定义 语法: def 函数名(形参): 函数体 return 调用 函数名(实参) 命名规则:和变量一样 1. 由数字, 字母, 下划线组成 2. 不能数字开头. 更不 ...

  10. Scrapy中的反反爬、logging设置、Request参数及POST请求

    常用的反反爬策略 通常防止爬虫被反主要有以下几策略: 动态设置User-Agent(随机切换User-Agent,模拟不同用户的浏览器信息.) 禁用cookies(也就是不启用cookies midd ...