winform之自定义控件

这样的一个控件 肯定得通过自定义控件来实现了
public class ProcessLabel : Control
{ public ProcessLabel()
{ //InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); } private int distance = ; public int Distance
{
get { return distance; }
set
{
distance = value;
Invalidate();
}
} private ImageList imagelist = new ImageList(); public ImageList ImageList
{
get { return imagelist; }
set
{
imagelist = value;
Invalidate();
}
} private List<KeyValuePair<string, string>> links = new List<KeyValuePair<string, string>>(); public List<KeyValuePair<string, string>> Links
{
get { return links; }
set
{
links = value;
Invalidate();
}
} protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Font enFont = new Font("新宋体", , FontStyle.Bold);
Rectangle rect = pe.ClipRectangle;
Graphics g = pe.Graphics;
float x = ;
float y = ;
float x1 = ;
float y1 = ;
float x2 = ;
float y2 = ;
int index = ;
if (Links.Count > )
{
foreach (KeyValuePair<string, string> kv in Links)
{
g.DrawString(kv.Key, enFont, new SolidBrush(Color.DodgerBlue), x, y);
SizeF sf = g.MeasureString(kv.Key, enFont);
x += (sf.Width + distance);
if (imagelist.Images.Count > )
{
Pen blackPenLeft;
Pen blackPenRight;
if (!string.IsNullOrEmpty(kv.Value))
{
x1 = x - distance - sf.Width / - imagelist.Images[].Width / ;
y1 = sf.Height;
g.DrawImage(imagelist.Images[], x1, y1);
blackPenLeft = new Pen(Color.Orange, );
x2 = x1 - ;
y2 = y1 + imagelist.Images[].Height;
g.DrawString(kv.Value, enFont, new SolidBrush(Color.DodgerBlue), x2, y2);
}
else
{
x1 = x - distance - sf.Width / - imagelist.Images[].Width / ;
y1 = sf.Height;
g.DrawImage(imagelist.Images[], x1, y1);
blackPenLeft = new Pen(Color.Black, );
}
if (index + < Links.Count && !string.IsNullOrEmpty(Links[index + ].Value))
{
blackPenRight = new Pen(Color.Orange, );
}
else
{
blackPenRight = new Pen(Color.Black, );
}
if (index == )
{
g.DrawLine(blackPenRight, x1 + imagelist.Images[].Width, y1 + imagelist.Images[].Height / , x1 + imagelist.Images[].Width / + sf.Width / + distance / , y1 + imagelist.Images[].Height / );
}
else if (index == Links.Count - )
{
g.DrawLine(blackPenLeft, x1 - , y1 + imagelist.Images[].Height / , x1 - sf.Width / - distance / , y1 + imagelist.Images[].Height / );
}
else
{
g.DrawLine(blackPenRight, x1 + imagelist.Images[].Width, y1 + imagelist.Images[].Height / , x1 + imagelist.Images[].Width / + sf.Width / + distance / , y1 + imagelist.Images[].Height / );
g.DrawLine(blackPenLeft, x1 - , y1 + imagelist.Images[].Height / , x1 - sf.Width / - distance / , y1 + imagelist.Images[].Height / );
}
index++;
}
}
if (x - distance + < this.Parent.Width)
{
this.Width = this.Parent.Width;
}
else
{
this.Width = Convert.ToInt32(x - distance + );
}
} } }
使用
ImageList myImageList = new ImageList();
string filePath1 = Application.StartupPath + "\\Images\\orangelink.png";
string filePath2 = Application.StartupPath + "\\Images\\blacklink.png";
myImageList.Images.Add(Image.FromFile(filePath1));
myImageList.Images.Add(Image.FromFile(filePath2));
processLabel1.ImageList = myImageList; List<KeyValuePair<string, string>> source = new List<KeyValuePair<string, string>>();
source.Add(new KeyValuePair<string,string>("下单","08:20"));
source.Add(new KeyValuePair<string,string>("接单","14:20"));
source.Add(new KeyValuePair<string,string>("配送","14:20"));
source.Add(new KeyValuePair<string, string>("收货", "15:20"));
source.Add(new KeyValuePair<string, string>("退货", "17:20"));
source.Add(new KeyValuePair<string, string>("退款", "19:20"));
source.Add(new KeyValuePair<string, string>("完毕", "21:20")); processLabel1.Links = source;
winform之自定义控件的更多相关文章
- WPF中添加Winform用户自定义控件
过程:创建WPF工程->创建Winform用户自定义控件工程->WPF中引用控件->添加到Xaml页面 1.首先在WPF工程的解决方案上右击选择添加新建项目: 选择Windows窗体 ...
- WinForm GDI+自定义控件总结(一)
前言 由于项目的原因好久没写博客了,也正是项目的原因开始系统的学习WinForm,从而接触到自定义控件的开发.自定义控件的开发有一定的难度,对开发者要求比较高,需要了解Windows运行的机制,熟悉w ...
- WinForm(C#)自定义控件之——RoundButton(圆形按钮)
最近需要做一个圆形的按钮,去CodeProject找了一下,发现有现成的可用,但不能完全满足我的需求.因此自己试着利用WinForm中的自定义组件功能,制作一个圆形按钮.圆形按钮小制作即将开始之前,先 ...
- winform制作自定义控件(入门)
原文链接:http://blog.csdn.net/bychentufeiyang/article/details/7081402 与原文基本一致,只是例子变成VS2012环境,语言采用博主常用的 ...
- WinForm创建自定义控件
虽然VS为我们提供了很多控件可以使用,但有时候这些控件仍然不能满足我们的要求,比如我们要对部分控件进行一些个性化的定制,例如美化控件,这时候就需要自己绘制控件,或是在原有控件的基础上进行修改 自定义控 ...
- winform制作自定义控件
一 .概述Windows 窗体控件是可再次使用的组件,它们封装了用户界面功能,并且可以用于客户端 Windows 应用程序.“Windows 窗体”不仅提供了许多现成控件,还提供了自行开发控件的基础结 ...
- WinForm用户自定义控件,在主窗体加载时出现闪烁;调用用户控件出现闪烁,需要鼠标才能够显示
转载自:http://www.dotblogs.com.tw/rainmaker/archive/2012/02/22/69811.aspx 解决方案: 在调用用户控件的窗体里面添加一下代码: pro ...
- Winform 中 DesignMode 返回值不正确的问题。
本文转载:http://blog.csdn.net/sabty/article/details/5325260 以前也曾遇到这样的问题,不过影响不大也没有去详细了解.今天又重新遇到此问题,实在太不便. ...
- Winform下让你的DataGridView控件支持点语法(即显示list中的子对象属性)
前言: 不想看前言的直接去看正文吧!另外文末有彩蛋. DataGridView可以支持多种数据源格式,比如DataTable和List. DataTable没啥特殊的,本身就是一张二维的表,可以和Da ...
随机推荐
- Sublime 不自动打开上次未关闭的文件 设置方法
{ "font_size": 17, "hot_exit": false, "remember_open_files": false, &q ...
- using gulp
原 荐 gulp构建前端工程 半张一块 发布时间: 2016/07/27 16:22 阅读: 895 收藏: 4 点赞: 4 评论: 2 摘要 Gulp 是一个自动化工具,前端开发者可以使用它来处理常 ...
- nyist 593 Take it easy
http://acm.nyist.net/JudgeOnline/problem.php?pid=593 Take it easy 时间限制:1000 ms | 内存限制:65535 KB 难度: ...
- 数据库 SQL基础
数据库是用来存取数据的. 数据库类型: ACESS(比较小,存储少) SQL SERVER (.net) MySQL Oracle(java) 数据库:服务.界面 服务是可以操作的后台的程序. 界面是 ...
- JSP和servlet有什么区别?
JSP和servlet有什么区别? JSP是Servlet技术的扩展,本质上是Servlet的简易方式,更强调应用的外表表达. JSP编译后是"类servlet". Servlet ...
- start.s 解析(一)
可以参考 : http://blog.csdn.net/bluesummerg/article/details/5940452 (强大的反汇编) http://www.cnblogs.com/yanh ...
- 反射认识_03_改变成员变量Fields
包01:package ReflectionChange; public class ReflectionPoint_AB { String str1="access"; Stri ...
- mac工具-解析json visualJSON和JSON Accelerator这两款工具
- C语言 类型
int 2个字节或4个字节 根据平台而定, -32,768 到 32,767 或 -2,147,483,648 到 2,147,483,647 unsigned int 2或4个字节 0到655 ...
- C#与js的各种交互
今天遇到一个问题,查到不错的资料,放上来记录一下,以防忘记地址,算是我的笔记吧! 很多人都向在服务器端调用客户端的函数来操作,也就是在asp中调用javascript脚本中已经定义好的脚本函数.经过研 ...