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. APT32入侵我国,试图窃取COVID-19相关情报

    新闻一篇: 一直以来,APT32都以东南亚为攻击目标,并且是近几年来针对中国大陆进行攻击活动最活跃的APT攻击组织,没有之一.此次再将目标对准中国,与新冠疫情离不开关系. 4月22日,Fireye发布 ...

  2. 2层感知机(神经网络)实现非线性回归(非线性拟合)【pytorch】

    import torch import numpy import random from torch.autograd import Variable import torch.nn.function ...

  3. Java 学习线路图

    学习是一个循序渐进的过程,是一件非常难得坚持的事情.如果真的想学Java,一定要下定决心! 这里我分享给你的Java学习线路图,希望对你有帮助,以下为2020年更新版本,黑马君在2020年更新了Jav ...

  4. cocos2dx初体验

    我们创建工程后总会自带一个HelloWorld类,短短的几行代码就出来了一个游戏的雏形,请问我们真的理解它了吗?如果我们能早一点弄明白这几行代码,我们或许会比现在走得更远. 理解HelloWorld类 ...

  5. Lambda表达式最佳实践

    简介 Lambda表达式java 8引入的函数式编程框架.之前的文章中我们也讲过Lambda表达式的基本用法. 本文将会在之前的文章基础上更加详细的讲解Lambda表达式在实际应用中的最佳实践经验. ...

  6. QML-AES加解密小工具

    Intro 为了解码网课视频做的小工具,QML初学者可以参考一下. 项目地址 Todo 在插入新条目时,ListView不会自动根据section进行重排,因此出现同一个文件夹重复多次的现象.目测强行 ...

  7. 打造更好用的 EF 自动审计

    打造更好用的 EF 自动审计 Intro 上次基于 EF Core 实现了一个自动审计的功能,详细可以参考 https://www.cnblogs.com/weihanli/p/auto-audit- ...

  8. 使用react脚手架create-react-app创建react应用

    Create React App是一种官方支持的创建单页React应用程序的方法.它提供了一个没有配置的现代构建设置. 一.全局安装脚手架: npm install -g create-react-a ...

  9. 第 38 章 OCR - Optical Character Recognition

    38.1. Tesseract 查找Tesseract安装包 $ apt-cache search Tesseract ocrodjvu - tool to perform OCR on DjVu d ...

  10. sphinx的使用

    1.下载地址 http://sphinxsearch.com/downloads/release/ 2.将其解压到D:\sphinx,并在D:\sphinx下新建目录data(用来存放索引文件)与lo ...