WinForm 自定义控件 - RooF
由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的更多相关文章
- C# winform 自定义控件
近来因为项目的问题,开始研究winform自定义控件,这篇主要是将自定义控件的属性在属性编辑器中可编辑,如果你对自定义控件比较了解的,就不用继续往下看了 首先,我创建了一个类UserButton,继承 ...
- C#winform自定义控件模拟设计时界面鼠标移动和调节大小、选中效果
要想玩转Winform自定义控件需要对GDI+非常熟悉,对常用的控件有一些了解,好选择合适的基类控件来简化. 要点说明及代码 1)定义接口: using System; using System.Wi ...
- Winform自定义控件实例
本文转自http://www.cnblogs.com/hahacjh/archive/2010/04/29/1724125.html 写在前面: .Net已经成为许多软件公司的选择,而.Net自定义W ...
- winform 自定义控件:半透明Loading控件
winform 自定义控件:半透明Loading控件 by wgscd date:2015-05-05 效果: using System;using System.Drawing;using Sys ...
- c#Winform自定义控件-目录
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (二)c#Winform自定义控件-按钮
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (三)c#Winform自定义控件-有图标的按钮
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (四)c#Winform自定义控件-选择按钮组
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (七)c#Winform自定义控件-进度条
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
随机推荐
- LF模式解决的问题
一说起Leader/Followers并发模式,都会与Half-Async/Half-Sync并发模式进行比较,说LF模式更加高性能,成了一个高性能名词标签 符号,相反HA/HS仿佛成了一个低性能的名 ...
- SQL Server Management Studio 安装流程
数据库的操作需要使用SQL Server Management Studio,不过也可以使用其他的: 下面是安装操作的步骤:如果你下载的压缩包,你需要先解压到一个文件夹里,然后双击setup.exe, ...
- Spring Cloud Alibaba(四)实现Dubbo服务消费
本项目演示如何使用 Spring Cloud Alibaba 完成 Dubbo 的RPC调用. Spring Cloud与Dubbo Spring Cloud是一套完整的微服务架构方案 Dubbo是国 ...
- 性能测试——记XX银行保全项目性能问题分析优化
记XX银行保全项目性能问题分析优化 数据库问题也许是大部分性能问题的关注点,但是JAVA应用与数据库交互的关节,JDBC 就像是我们人体的上半身跟下半身的腰椎,支持上半身,协调下半身运动的重要支撑点. ...
- Rust更换Crates源
Rust编译时遇到如下问题: Downloading futures v0.1.19 warning: spurious network error (2 tries remaining): [28] ...
- pymongo的基本操作和使用
MongoDB简介 MongoDB是一个开源的文档类型数据库,它具有高性能,高可用,可自动收缩的特性.MongoDB能够避免传统的ORM映射从而有助于开发. 文档 在MongoDB中,一行纪录就是一个 ...
- 封装一个适用于vue的 jsonp
import originJsonp from 'jsonp' export default function jsonp(url, data, option) { return new Promis ...
- 版本控制神器——git的基本使用
git基础命令 安装git windows的话,直接下载安装即可 Linux Ubuntu安装,apt-get install git Linux Centos安装,yum install git 配 ...
- 【Android - 自定义View】之View的事件分发机制
参考资料: View事件分发:http://blog.csdn.net/pi9nc/article/details/9281829 ViewGroup事件分发:http://blog.csdn.net ...
- diff()函数的使用
1.diff():返回略微迭代(lagged)的或滞后的不同(iterated diferences). > x<-cumsum(cumsum(1:10)) > x [1] 1 4 ...