1.解决方案下添加新建项目新建类库
2. 在项目下添加新建项选择新建组件类
3.先引用,然后导入两个命名空间
4.因为是扩展控件,把继承自Component改成继承自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扩展控件的更多相关文章

  1. 多年前写的文本框扩展控件(有ValueChanging事件等),已放github

    本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 阅读目录 介绍 起因 代码 使用 GitHub ...

  2. JavaFX的扩展控件库ControlsFX介绍

    声明:   本博客文章原创类别的均为个人原创,版权所有.转载请注明出处: http://blog.csdn.net/ml3947,另外本人的个人博客:http://www.wjfxgame.com. ...

  3. WPF自定义控件(三)の扩展控件

    扩展控件,顾名思义就是对已有的控件进行扩展,一般继承于已有的原生控件,不排除继承于自定义的控件,不过这样做意义不大,因为既然都自定义了,为什么不一步到位呢,有些不同的需求也可以通过此来完成,不过类似于 ...

  4. QGEditors.WinForms WinForms下使用的部分扩展控件

    Nuget: https://www.nuget.org/packages/QGEditors.WinForms/ PM> Install-Package QGEditors.WinForms ...

  5. 验证控件插图扩展控件ValidatorCalloutExtender(用于扩展验证控件)和TextBoxWatermarkExtender

    <asp:ScriptManager ID="ScriptManager1" runat="server">  </asp:ScriptMan ...

  6. [转载]ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件

    作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...

  7. ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件

    本篇讲解三个容器类控件. 一.面板控件 Ext.Panel 一个面板控件包括几个部分,有标题栏.工具栏.正文.按钮区.标题栏位于最上面,工具栏可以在四个位置放置,围绕中间部分正文,按钮区位于最小方.下 ...

  8. 2016.5.30实现透明Panel及控件置顶的方法

    想放置一个透明Panel在某控件上端,实现效果是可透过此Panel看见下面控件,但鼠标点击却无任何反应. 1.新建置自定义Panel类 using System; using System.Colle ...

  9. IExtenderProvider,c#组件扩展控件属性

    [ProvideProperty("IsEnabled", typeof(LayoutControlItem)), ToolboxItemFilter("System.W ...

随机推荐

  1. leetcode-0543 二叉树的直径

    题目地址https://leetcode-cn.com/problems/diameter-of-binary-tree/ 递归+BFS(暴力解法) 我们可以考虑在每个节点时,都去计算该节点左子树和右 ...

  2. C# WCF之用接口创建服务契约、部署及客户端连接

    服务契约描述了暴露给外部的类型(接口或类).服务所支持的操作.使用的消息交换模式和消息的格式.每个WCF服务必须实现至少一个服务契约.使用服务契约必须要引用命名空间System.ServiceMode ...

  3. Python神库分享之geoip2 IP定位库

    先安装这两个 pip install python-geoip-geolite2 -i https://pypi.douban.com/simple pip install geoip2 然后下载资源 ...

  4. php二维数组的排序

    /**  * @desc arraySort php二维数组排序 按照指定的key 对数组进行排序  * @param array $arr 将要排序的数组  * @param string $key ...

  5. Spring Security Oauth2 使用 token 访问资源服务器出现异常:Invalid token does not contain resource id (oauth2)

    异常如图 查看资源服务器的日志 p.a.OAuth2AuthenticationProcessingFilter : Authentication request failed: error=&quo ...

  6. SpringCloud入门(十一):Sleuth 与 Zipkin分布式链路跟踪

    现今业界分布式服务跟踪的理论基础主要来自于 Google 的一篇论文<Dapper, a Large-Scale Distributed Systems Tracing Infrastructu ...

  7. Linux监听磁盘使用情况

    前阵子服务器磁盘写满了,导致项目出了很多奇怪的问题,比如文件上传不了(这个很好理解),还有登录时验证码无法加载(现在依旧不知道原因,项目的验证码图片是只在内存中生成的BufferedImage对象,不 ...

  8. PHP字符串全排列算法

    <?php /** * PHP字符串全排列算法 */ $results = []; $arr = []; function bfs($start) { global $arr; global $ ...

  9. CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)

    Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...

  10. 数学--数论--HDU1222 狼和兔子(最大公约数)

    问题描述 有一座周围有n个洞的小山.孔从0到n-1有符号. 兔子必须藏在其中一个洞中.狼以逆时针方向搜索兔子.他第一个进入的洞是一个用0签名的洞.然后,他将每m个洞进入一个洞.例如,m = 2和n = ...