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 ...
随机推荐
- FB面经prepare: Task Schedule
每种task都有冷却时间,比如task1执行后,要经过interval时间后才能再次执行,求总共所需时间. 用HashMap保存每一个task的下一次可以开始执行的最早时间 package TaskS ...
- SQL 数据库 函数
1.数学函数:操作一个数据,返回一个结果 --取上限ceiling select code,name,ceiling(price) from car ; --取下限 floor select floo ...
- 使用Mysql修改密码命令更改root的密码
使用Mysql修改密码命令更改root的密码. 进入Mysql数据库命令行方式有两种方式: 方式一:在Mysql开始菜单里包含Mysql命令行客户端,只要点击输入root的密码即可进入. 方式二:在D ...
- C++如何通过一个响应事件接受多个控件消息
在空的Form里加个Button,写入void __fastcall TForm1::Button1Click(TObject *Sender){ for (long k=0; k<5; k++ ...
- NVL 和NVL2函数
NVL 和NVL2函数 NVL函数: nvl(exp1,exp2) -->判断exp1是否是null,如果exp1不是则返回exp1的值,如果exp1为null则返回exp2 nvl2函数: n ...
- linux第10天 msg消息队列
cat /proc/sys/kernel/msgmax最大消息长度限制 cat /proc/sys/kernel/msgmnb消息队列总的字节数 cat /proc/sys/kernel/msgmni ...
- web server与app server有什么不同
简单来说,web服务器提供页面给浏览器,而app服务器提供客户端可以调用的接口.具体而言,我们可以说: Web服务器处理HTTP请求,而app服务器基于多种不同的协议,处理应用程序的逻辑问题. 以下将 ...
- 当执行php脚本时用户关闭浏览器会发生什么?
2008年8月16日 1,152 views 发表评论 阅读评论 如果一段php脚本执行插入数据到mysql的操作. 一般情况下,由于php脚本在服务器上执行,此时用户虽然关闭了浏览器,但是服务器端的 ...
- RobotFramework 安装配置(一)
服务器接口的测试框架的选择,最后选中了 RobotFramework ,原因一:能有效的管理测试用例,,支持批量执行,能实现关键字驱动或者数据驱动.原因二:支持测试人员可以使用Python和java创 ...
- Imageloarder
首先需要加载jar包,和在配置文件中配置Mainactivity.javapackage com.baidu.day13_2imageloader; import com.nostra13.unive ...