2.C#Panel扩展控件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics; using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Drawing;
namespace FJZControl
{
public partial class FJZPanel : Panel
{
public FJZPanel()
{
InitializeComponent();
} public FJZPanel(IContainer container)
{
container.Add(this); InitializeComponent();
}
#region 属性
private Color headBackColor = Color.LimeGreen;
[Category("我的自定义Panel控件属性")]
[Description("标题的背景颜色")]
public Color HeadBackColor
{
get
{
return headBackColor;
} set
{
headBackColor = value; this.Invalidate();
}
} private Color headForeColor = Color.Black;
[Category("我的自定义Panel控件属性")]
[Description("标题的背景颜色")]
public Color HeadForeColor
{
get
{
return headForeColor;
} set
{
headForeColor = value; this.Invalidate();
}
} private int headHeight = ;
[Category("我的自定义Panel控件属性")]
[Description("标题的高度")]
public int HeadHeight
{
get
{
return headHeight;
} set
{
headHeight = value;
this.Invalidate();
}
} private string headText = "标题名称";
[Category("我的自定义Panel控件属性")]
[Description("标题的名称")]
public string HeadText
{
get { return headText; }
set
{
this.headText = value;
this.Invalidate();
} } private float linearScale=0.4f;
[Category("我的自定义Panel控件属性")]
[Description("渐变程度")]
public float LinearScale
{
get
{
return linearScale;
} set
{
linearScale = value;
this.Invalidate();
}
}
#endregion #region 字段
Graphics g;
Pen p;
SolidBrush sb;
#endregion
#region 方法
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//自定义绘制过程 //获取这个画布
g = e.Graphics; //设置画布
SetGrahics(); //第一步:画标题框
using (LinearGradientBrush brush = new LinearGradientBrush(new PointF(, ), new PointF(, this.headHeight), GetStartLinearColor(this.headBackColor), this.headBackColor))
{
g.FillRectangle(brush, new RectangleF(, , this.Width, this.headHeight));
}
//第二步:标题
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
using(SolidBrush sb=new SolidBrush(this.headForeColor))
{
g.DrawString(this.headText, this.Font, sb,new RectangleF( ,,this.Width, this.headHeight), sf);
}
//第三步:画边框
using(Pen p=new Pen(this.headBackColor))
{
g.DrawRectangle(p, , , this.Width-, this.Height-);
g.DrawLine(p, , this.HeadHeight, this.Width - , this.headHeight - );
}
}
//设置画布属性
private void SetGrahics()
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.SmoothingMode = SmoothingMode.HighQuality; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
g.TextRenderingHint = TextRenderingHint.AntiAlias; } //获取
private Color GetStartLinearColor(Color EndLinearColor)
{
return Color.FromArgb((int)(EndLinearColor.R + ( - EndLinearColor.R) * this.linearScale), (int)(EndLinearColor.G + ( - EndLinearColor.G) * this.linearScale), (int)(EndLinearColor.B + ( - EndLinearColor.B) * this.linearScale));
}
#endregion
}
}
效果如下:

2.C#Panel扩展控件的更多相关文章
- 多年前写的文本框扩展控件(有ValueChanging事件等),已放github
本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 阅读目录 介绍 起因 代码 使用 GitHub ...
- JavaFX的扩展控件库ControlsFX介绍
声明: 本博客文章原创类别的均为个人原创,版权所有.转载请注明出处: http://blog.csdn.net/ml3947,另外本人的个人博客:http://www.wjfxgame.com. ...
- WPF自定义控件(三)の扩展控件
扩展控件,顾名思义就是对已有的控件进行扩展,一般继承于已有的原生控件,不排除继承于自定义的控件,不过这样做意义不大,因为既然都自定义了,为什么不一步到位呢,有些不同的需求也可以通过此来完成,不过类似于 ...
- QGEditors.WinForms WinForms下使用的部分扩展控件
Nuget: https://www.nuget.org/packages/QGEditors.WinForms/ PM> Install-Package QGEditors.WinForms ...
- 验证控件插图扩展控件ValidatorCalloutExtender(用于扩展验证控件)和TextBoxWatermarkExtender
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptMan ...
- [转载]ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件
作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...
- ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件
本篇讲解三个容器类控件. 一.面板控件 Ext.Panel 一个面板控件包括几个部分,有标题栏.工具栏.正文.按钮区.标题栏位于最上面,工具栏可以在四个位置放置,围绕中间部分正文,按钮区位于最小方.下 ...
- 2016.5.30实现透明Panel及控件置顶的方法
想放置一个透明Panel在某控件上端,实现效果是可透过此Panel看见下面控件,但鼠标点击却无任何反应. 1.新建置自定义Panel类 using System; using System.Colle ...
- IExtenderProvider,c#组件扩展控件属性
[ProvideProperty("IsEnabled", typeof(LayoutControlItem)), ToolboxItemFilter("System.W ...
随机推荐
- centos7下端口映射
firewall-cmd --zone=external --add-forward-port=port=:proto=tcp:toport=:toaddr=192.168.10.10 --perma ...
- [Qt] 文本文件读写, 摘自官方文档
Reading Files Directly The following example reads a text file line by line: QFile file("in.txt ...
- IDEA设置导入主题样式皮肤,加入背景图片
主题下载地址:http://www.riaway.com/theme.php 里面有很多主题,看个人喜好,这里我用的Monokai Sublime Text 3. 导入主题打开IDEA,找到File ...
- Django项目打包
Django项目打包 这是目前开发完成的project目录树.我们要打包其中的polls app. (v_python3.6) thinkt@linux-pw37:~/PycharmProjects/ ...
- 编写C#程序的IDE
编写C#程序,在Windows平台下,除了昂贵的Visual Studio.NET这个正宗的工具外,你还了解哪些? 听说有个Eclipse,IBM投钱开发的开源工具,有人也做了个for .NET的pl ...
- 【K8S】K8S部署Metrics-Server服务
写在前面 在新版的K8S中,系统资源的采集均使用Metrics-Server服务,可以通过Metrics-Server服务采集节点和Pod的内存.磁盘.CPU和网络的使用率等信息. 读者可参考< ...
- 快放弃你的管家软件吧! Part 2 强制删除
在Windows系统中,难免会遇到用常规方法无法删除文件的情况. 经常有遇到过一些情况? 软件卸载了,有些文件夹就是删不掉,提示被占用,mmp,这时候你肯定想到了360文件粉碎机! mmp,我就删个文 ...
- 一只简单的网络爬虫(基于linux C/C++)————读取命令行参数及日志宏设计
linux上面的程序刚开始启动的时候一般会从命令行获取某些参数,比如以守护进程运行啊什么的,典型的例子就是linux下的man,如下图所示 实现该功能可以使用getopt函数实现,该函数在头文件uni ...
- 题目分享V
题意:现在两个人做游戏,每个人刚开始都是数字1,谁赢了就能乘以k^2,输的乘以k(k可以是任意整数,每次不一定相同)现在给你最终这两个人的得分,让你判断是否有这个可能,有可能的话Yes,否则No. 分 ...
- RocketMQ-架构篇
RocketMQ-架构篇 1.Broker Broker是RocketMQ的服务端组件之一,所有消息存储在Broker上,所有的投递.消费请求也都由Broker进行处理.Broker是有状态的应用,本 ...