(三)c#Winform自定义控件-有图标的按钮
前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果觉得写的还行,请点个 star 支持一下吧
欢迎前来交流探讨: 企鹅群568015492 
目录
https://www.cnblogs.com/bfyx/p/11364884.html
准备工作
该控件将继承控件UCBtnExt,如果你还对UCBtnExt不了解的下,
请移步 (二)c#Winform自定义控件-按钮 查看
首先我们了解下要做的是什么,我们需要做一个可以自定义填充颜色,有圆角边框,有角标的,有图标的按钮
开始
添加一个用户控件UCBtnImg 继承UCBtnExt
添加属性
private string _btnText = "自定义按钮";
/// <summary>
/// 按钮文字
/// </summary>
[Description("按钮文字"), Category("自定义")]
public new string BtnText
{
get { return _btnText; }
set
{
_btnText = value;
lbl.Text = " " + value;
lbl.Refresh();
}
}
/// <summary>
/// 图片
/// </summary>
[Description("图片"), Category("自定义")]
public Image Image
{
get
{
return this.imageList1.Images[];
}
set
{
this.imageList1.Images.Clear();
this.imageList1.Images.Add(value);
this.lbl.ImageIndex = ;
}
}
下面看一下完整代码
// 版权所有 黄正辉 交流群:568015492 QQ:623128629
// 文件名称:UCBtnImg.cs
// 创建日期:2019-08-15 15:58:07
// 功能描述:按钮
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace HZH_Controls.Controls
{
/// <summary>
///
/// </summary>
public partial class UCBtnImg : UCBtnExt
{
private string _btnText = "自定义按钮";
/// <summary>
/// 按钮文字
/// </summary>
[Description("按钮文字"), Category("自定义")]
public new string BtnText
{
get { return _btnText; }
set
{
_btnText = value;
lbl.Text = " " + value;
lbl.Refresh();
}
}
/// <summary>
/// 图片
/// </summary>
[Description("图片"), Category("自定义")]
public Image Image
{
get
{
return this.imageList1.Images[];
}
set
{
this.imageList1.Images.Clear();
this.imageList1.Images.Add(value);
this.lbl.ImageIndex = ;
}
} public UCBtnImg()
{
InitializeComponent();
base.BtnForeColor = ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
base.BtnFont = new System.Drawing.Font("微软雅黑", 17F);
base.BtnText = " 自定义按钮";
}
}
}
namespace HZH_Controls.Controls
{
partial class UCBtnImg
{
/// <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.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UCBtnImg));
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
//
// lbl
//
//this.lbl.Font = new System.Drawing.Font("微软雅黑", 17F);
//this.lbl.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(102)))), ((int)(((byte)(102)))), ((int)(((byte)(102)))));
this.lbl.ImageIndex = ;
this.lbl.ImageList = this.imageList1;
this.lbl.Padding = new System.Windows.Forms.Padding(, , , );
this.lbl.Text = " 自定义按钮";
this.lbl.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(, "back.png");
//
// BtnBack
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.Name = "BtnBack";
this.ResumeLayout(false); } #endregion private System.Windows.Forms.ImageList imageList1;
}
}
用处及效果
用处:按钮需要显示图标时使用
效果:

最后的话
如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧
(三)c#Winform自定义控件-有图标的按钮的更多相关文章
- 第二百三十七节,Bootstrap图标菜单按钮组件
Bootstrap图标菜单按钮组件 学习要点: 1.小图标组件 2.下拉菜单组件 3.按钮组组件 4.按钮式下拉菜单 本节课我们主要学习一下 Bootstrap 的三个组件功能:小图标组件.下拉菜单组 ...
- (四十八)c#Winform自定义控件-下拉按钮
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- c#Winform自定义控件-目录
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (八十二)c#Winform自定义控件-穿梭框
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- winform 自定义控件(高手)
高手推荐:https://www.cnblogs.com/bfyx/p/11364884.html c#Winform自定义控件-目录 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件 ...
- (二)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 ...
随机推荐
- 论文阅读 <Relocalization, Global Optimization and Map Merging for Monocular Visual-Inertial SLAM>
看了一下港科的基于vins拓展的论文<relocalization, global optimization and merging for vins>,在回环的实现部分总体没有什么变化, ...
- 最好的导航分割栏,分割线,实现底部透明,纯css
<div class="Ui_Ct_Line padding_5"> <div>为您推荐</div> </div> .Ui_Ct_L ...
- 网络编程模型及TCP、UDP编程设计
1.Linux网络模型 Linux网络编程--->>>socket套接字的编程 2.TCP网络模型 ...
- 洛谷P2172 [国家集训队]部落战争 题解
题目链接:https://www.luogu.org/problemnew/show/P2172 分析: 不要被[国家集训队]的标签吓到,其实这题不是很难. 本题可以对比P4304 [TJOI2013 ...
- React躬行记(3)——组件
组件(Component)由若干个React元素组成,包含属性.状态和生命周期等部分,满足独立.可复用.高内聚和低耦合等设计原则,每个React应用程序都是由一个个的组件搭建而成,即组成React应用 ...
- C#5.0新增功能02 调用方信息
连载目录 [已更新最新开发文章,点击查看详细] 通过使用调用方信息特性,可获取有关方法的调用方的信息. 可以获取源代码的文件路径.源代码中的行号和调用方的成员名称. 此信息有助于跟踪.调试和创建 ...
- 关于python3与python2同时存在情况下导入pyqt失败解决记录
最近感觉tkinter功能还是比较不适合新手做出高大上的界面,故开始使用pyqt,通过pip安装好了之后,利用qt设计师设计好界面之后,cmd运行之,报错提示没有找到pyqt5模块,IDE运行能正常加 ...
- JSON的简单使用之提取多层嵌套的JSON(C#)
JSON.NET(http://json.codeplex.com/)使用来将.NET中的对象转换为JSON字符串(序列化?),或者将JSON字符串转换为.NET中已有类型的对象(反序列化?) 反序列 ...
- Cocos2d-x 3.x中自定义渲染功能
1.第一种方法针对的是整个图层的渲染 重写visit()函数,并且在visit()函数中直接向CommandQueue添加CustomCommand,设置好回调函数. ...
- 重复造轮子系列——基于Ocelot实现类似支付宝接口模式的网关
重复造轮子系列——基于Ocelot实现类似支付宝接口模式的网关 引言 重复造轮子系列是自己平时的一些总结.有的轮子依赖社区提供的轮子为基础,这里把使用过程的一些觉得有意思的做个分享.有些思路或者方法在 ...