由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. expect 自动填充密码

    它的脚本以#!/usr/bin/expect开头,执行时用expoct,而不是bash.我的一个给samba自动创建用户并且自动填写默认密码的脚本如下: vim smb_passwd.exp #!/u ...

  2. opencv 4 图像处理(漫水填充,图像金字塔与图片尺寸缩放,阈(yu)值化)

    漫水填充 实现漫水填充算法:floodFill函数 简单调用范例 #include <opencv2/opencv.hpp> #include <opencv2/imgproc/im ...

  3. C# 彻底搞懂async/await

    前言 Talk is cheap, Show you the code first! private void button1_Click(object sender, EventArgs e) { ...

  4. eNSP仿真软件之利用单臂路由实现VLAN间路由

    1. 实验原理 以太网中,通常会使用VLAN技术隔离二层广播域来减少广播的影响,并增强网络的安全性和可管理性.其缺点是同时也严格地隔离了不同VLAN之间的任何二层流量,使分属于不同VLAN的用户不能直 ...

  5. 父组件向子组件传值时,值已经传过来却没有触发子组件的watch监听,解决~

    需求: 父组件像封装的子组件传值  (父组件属性传值,子组件props接受)   子组件接受后经过处理回显页面; 预想:子组件接受值 , 经过watch监听,在监听中处理数据,回显数据; 问题:子组件 ...

  6. wincap linux部署

    1.4.1 linux下安装Winpcap a) 下载Winpcap的源码:https://www.winpcap.org/devel.htm b) 上传源码包“WpcapSrc_4_1_3.zip” ...

  7. Linux 命令之 scp 命令详解

    Linux 命令之 scp 命令详解 一.scp 简介 scp 命令用于不同主机之间复制文件和目录. scp 是 secure copy 的缩写,是 基于 ssh 协议进行安全的远程文件拷贝命令. s ...

  8. C语言|博客作业11

    问题 回答 这个作业属于哪个课程 C语言程序设计ll 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/SE2019-2/homework/10127 我在 ...

  9. WebGL简易教程(十四):阴影

    目录 1. 概述 2. 示例 2.1. 着色器部分 2.1.1. 帧缓存着色器 2.1.2. 颜色缓存着色器 2.2. 绘制部分 2.2.1. 整体结构 2.2.2. 具体改动 3. 结果 4. 参考 ...

  10. 使用生成对抗网络(GAN)生成手写字

    先放结果 这是通过GAN迭代训练30W次,耗时3小时生成的手写字图片效果,大部分的还是能看出来是数字的. 实现原理 简单说下原理,生成对抗网络需要训练两个任务,一个叫生成器,一个叫判别器,如字面意思, ...