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 ...
随机推荐
- Pytorch实现的语义分割器
使用Detectron预训练权重输出 *e2e_mask_rcnn-R-101-FPN_2x* 的示例 从Detectron输出的相关示例 使用Detectron预训练权重输出 *e2e_keypoi ...
- 如何保证kafka消息不丢失
背景 这里的kafka值得是broker,broker消息丢失的边界需要对齐一下: 1 已经提交的消息 2 有限度的持久化 如果消息没提交成功,并不是broke丢失了消息: 有限度的持久化(broke ...
- 关于synergy的问题
报错信息主要集中在以下两条: ERROR: ssl error occurred (system call failure) ERROR: eof violates ssl protocol 通过查找 ...
- 文件上传漏洞(pikachu)
文件上传漏洞 文件上传功能在web应用系统很常见,比如很多网站注册的时候需要上传头像,附件等等.当用户点击上传按钮后,后台会对上传的文件进行判断,比如是否是指定的类型.后缀名.大小等等,然后将其按照设 ...
- Linux硬盘分区知识
前言 硬盘使用前,一般要分区,格式化(创建文件系统)<== 存放数据 类比,房子使用前,一般要隔断,装修,买家具,再住人. 分区 一块硬盘: 主分区.扩展分区.逻辑分区 主分区+扩展分区的数量& ...
- VB中使用字典存储类对象
2019独角兽企业重金招聘Python工程师标准>>> NODE类 Public pNext As NODE Public pPrev As NODE Public data As ...
- 2019/2/20训练日记+map/multi map浅谈
Most crossword puzzle fans are used to anagrams - groups of words with the same letters in different ...
- 2019.06.18训练日记(赞FLS)
之前打了几场比赛,有很多题没做出来,这些题无论是知识点不会,还是说在当时时间和思路的影响下没有做出来,这都应该做出来,至少现在必须做出来,本来打算专心复习,分数高了,好保研,但是想了想如果局限于只把学 ...
- 3) drf 框架生命周期 请求模块 渲染模块 解析模块 自定义异常模块 响应模块(以及二次封装)
一.DRF框架 1.安装 pip3 install djangorestframework 2.drf框架规矩的封装风格 按功能封装,drf下按不同功能不同文件,使用不同功能导入不同文件 from r ...
- 题目分享Q
题意:给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 分析:这可以说是换根法的裸题吧 首先考虑对一个给定的根如何计算,这应该是最简单的那种树形dp吧甚至可能都不算dp(好像 ...