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. Mac剪切板中的PNG保存到文件swift

    SwiftGG 教程大全 中文翻译 命令行工具开发教程 Line Programs on macOS Tutorial swift4,较详细 Swift基础中需要注意的点 NSPasteboard M ...

  2. ElasticSearch的高级复杂查询:非聚合查询和聚合查询

    一.非聚合复杂查询(这儿展示了非聚合复杂查询的常用流程) 查询条件QueryBuilder的构建方法 1.1 精确查询(必须完全匹配上,相当于SQL语句中的“=”) ① 单个匹配 termQuery ...

  3. java redis面试专题(附答案)

    1.什么是Redis?简述它的优缺点? Redis的全称是:Remote Dictionary.Server,本质上是一个Key-Value类型的内存数据库,很像 memcached,整个数据库统统加 ...

  4. python爬虫实战之爬取智联职位信息和博客文章信息

    1.python爬取招聘信息 简单爬取智联招聘职位信息 # !/usr/bin/env python # -*-coding:utf-8-*- """ @Author  ...

  5. 单源最短路问题--朴素Dijkstra & 堆优化Dijkstra

    许久没有写博客,更新一下~ Dijkstra两种典型写法 1. 朴素Dijkstra     时间复杂度O(N^2)       适用:稠密图(点较少,分布密集) #include <cstdi ...

  6. 【Linux常见命令】echo命令

    echo - display a line of text 打印输出内容的常用命令,可以结合重定向>和追加>>对文件进行覆盖或追加内容. 语法: echo [SHORT-OPTION ...

  7. 《Splunk智能运维实战》——1.7 为本书加载样本数据

    本节书摘来自华章计算机<Splunk智能运维实战>一书中的第1章,第1.7节,作者 [美]乔史·戴昆(Josh Diakun),保罗R.约翰逊(Paul R. Johnson),德莱克·默 ...

  8. ELSE 技术周刊(2017.12.25期)

    业界动态 V8 release v6.4 V8引擎发布v6.4,在速度和内存优化上又带来了一些提升.对于instanceof操作符的优化,带来了3.6x速度提升,同时使得uglify-js提高了15- ...

  9. JVM调优方法笔记

    1.性能工具介绍 jvisualvm jmap jstat jstack/threaddump jprofiler jmeter 2.性能调优4步骤 重现问题 定位问题 模拟问题 解决问题 http: ...

  10. Axios 拦截器中添加headers 属性

    描述: 已在网上查过怎么在 interceptors 中对header进行处理,// http request 拦截器 axios.interceptors.request.use( config = ...