1。新建一个项目
2。添加一个用户控件“PaneCaption.vb”
3。[操作]调整控件大小为150×30
4。打开代码编辑器:
Imports System.Drawing.Drawing2D

Imports System.ComponentModel

Public Class PaneCaption

' 常量设置
   Private Class ConstsPublic Const DefaultHeight As Integer = 20Public Const DefaultFontName As String = "arial"Public Const DefaultFontSize As Integer = 9Public Const PosOffset As Integer = 4End Class
' 内部成员
 Private _active As Boolean = FalsePrivate _antiAlias As Boolean = TruePrivate _allowActive As Boolean = TruePrivate _colorActiveText As Color = Color.BlackPrivate _colorInactiveText As Color = Color.WhitePrivate _colorActiveLow As Color = Color.FromArgb(255, 165, 78)Private _colorActiveHigh As Color = Color.FromArgb(255, 225, 155)Private _colorInactiveLow As Color = Color.FromArgb(3, 55, 145)Private _colorInactiveHigh As Color = Color.FromArgb(90, 135, 215)' 绘图对象Private _brushActiveText As SolidBrushPrivate _brushInactiveText As SolidBrushPrivate _brushActive As LinearGradientBrushPrivate _brushInactive As LinearGradientBrushPrivate _format As StringFormat' 公共参数' 控件标题<Category("Appearance"), Browsable(True), _DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _Description("Text that is displayed in the label.")> _Public Shadows Property Text() As StringGetReturn MyBase.TextEnd GetSet(ByVal Value As String)MyBase.Text = ValueInvalidate()End SetEnd Property' 标题栏是否激活<Description("The active state of the caption, draws the caption with different gradient colors."), _Category("Appearance"), DefaultValue(False)> _Public Property Active() As BooleanGetReturn _activeEnd GetSet(ByVal value As Boolean)_active = valueInvalidate()End SetEnd Property' 是否应该包含活动和非活动状态<Description("True always uses the inactive state colors, false maintains an active and inactive state."), _Category("Appearance"), DefaultValue(True)> _Public Property AllowActive() As BooleanGetReturn _allowActiveEnd GetSet(ByVal value As Boolean)_allowActive = valueInvalidate()End SetEnd Property' 防锯齿模式<Description("If should draw the text as antialiased."), _Category("Appearance"), DefaultValue(True)> _Public Property AntiAlias() As BooleanGetReturn _antiAliasEnd GetSet(ByVal value As Boolean)_antiAlias = valueInvalidate()End SetEnd Property

颜色属性

    ' 内部属性' 绘制标题的画刷Private ReadOnly Property TextBrush() As SolidBrushGetReturn DirectCast(IIf(_active AndAlso _allowActive, __brushActiveText, _brushInactiveText), SolidBrush)End GetEnd Property' 背景渐变色Private ReadOnly Property BackBrush() As LinearGradientBrushGetReturn DirectCast(IIf(_active AndAlso _allowActive, __brushActive, _brushInactive), LinearGradientBrush)End GetEnd Property' 构造函数Public Sub New()MyBase.New()' 窗体设计器调用InitializeComponent()' 设置双缓冲样式Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or _ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw, True)' 初始化高度Me.Height = Consts.DefaultHeight' 文本的格式_format = New StringFormat_format.FormatFlags = StringFormatFlags.NoWrap_format.LineAlignment = StringAlignment.Center_format.Trimming = StringTrimming.EllipsisCharacter' 初始化字体Me.Font = New Font(Consts.DefaultFontName, Consts.DefaultFontSize, FontStyle.Bold)' 创建GDI对象Me.ActiveTextColor = _colorActiveTextMe.InactiveTextColor = _colorInactiveText' 创建渐变颜色效果画刷CreateGradientBrushes()End Sub' 内部成员' 需要重绘标题Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)DrawCaption(e.Graphics)MyBase.OnPaint(e)End Sub' 绘制标题Private Sub DrawCaption(ByVal g As Graphics)' 背景g.FillRectangle(Me.BackBrush, Me.DisplayRectangle)' 标题If _antiAlias Theng.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasEnd If' 使用省略号时需要一个矩形Dim bounds As RectangleF = New RectangleF(Consts.PosOffset, 0, _Me.DisplayRectangle.Width - Consts.PosOffset, Me.DisplayRectangle.Height)g.DrawString(Me.Text, Me.Font, Me.TextBrush, bounds, _format)End Sub' 重写该函数,处理单击标题产生的事件Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)MyBase.OnMouseDown(e)If Me._allowActive Then Me.Focus()End SubProtected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)MyBase.OnSizeChanged(e)' 重绘CreateGradientBrushes()End SubPrivate Sub CreateGradientBrushes()' 允许重绘的高度和宽度条件If Me.Width > 0 AndAlso Me.Height > 0 ThenIf Not (_brushActive Is Nothing) Then _brushActive.Dispose()_brushActive = New LinearGradientBrush(Me.DisplayRectangle, __colorActiveHigh, _colorActiveLow, LinearGradientMode.Vertical)If Not (_brushInactive Is Nothing) Then _brushInactive.Dispose()_brushInactive = New LinearGradientBrush(Me.DisplayRectangle, __colorInactiveHigh, _colorInactiveLow, LinearGradientMode.Vertical)End IfEnd SubEnd Class

5。按F5编译并保存
6。 建立一个基类 “BasePane.vb”
该基类将使用到前面定义的面板标题类,也属于用户控件。提供对绘图、改变大小、焦点控制等事件进行处理的基本功能。
7。[操作]双击之前生成的用户控件PaneCaption加入到工作区,该操作将定义一个PaneCaption1的实例,改名为"caption"。注意:新的组建要在重新编译后才能在工具栏中出现。
8。打开代码编辑器:
’ Base class for the three panes. Draws caption at top with using

’ a different gradient fill if the pane is active or inactive.

Imports System.ComponentModel

Public Class BasePaneInherits System.Windows.Forms.UserControl' events' raise when the pane becomes activePublic Event PaneActive(ByVal sender As Object, ByVal e As EventArgs)' internal members' pane captionPrivate caption As PaneCaption' propertiesProtected ReadOnly Property CaptionControl() As PaneCaptionGetReturn captionEnd GetEnd Property<Description("The pane caption."), Category("Appearance")> _Public Property CaptionText() As StringGetReturn caption.TextEnd GetSet(ByVal value As String)caption.Text = valueEnd SetEnd PropertyPublic ReadOnly Property Active() As BooleanGetReturn caption.ActiveEnd GetEnd Property' ctorPublic Sub New()MyBase.New()' set double buffer stylesMe.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or _ControlStyles.AllPaintingInWmPaint Or ControlStyles.ResizeRedraw, True)' This call is required by the Windows.Forms Form Designer.InitializeComponent()End Sub

Windows Form Designer generated code

    ' internal methods' received focus, make this the active paneProtected Overrides Sub OnEnter(ByVal e As System.EventArgs)MyBase.OnEnter(e)caption.Active = TrueRaiseEvent PaneActive(Me, EventArgs.Empty)End Sub' lost focus, not the active paneProtected Overrides Sub OnLeave(ByVal e As System.EventArgs)MyBase.OnLeave(e)caption.Active = FalseEnd Sub' draw border around the paneProtected Overrides Sub OnPaint(ByVal e As PaintEventArgs)Dim rc As New Rectangle(0, 0, Me.Width - 1, Me.Height - 1)rc.Inflate(-Me.DockPadding.All + 1, -Me.DockPadding.All + 1)e.Graphics.DrawRectangle(SystemPens.ControlDark, rc)MyBase.OnPaint(e)End SubProtected Overrides Sub OnResize(ByVal e As System.EventArgs)MyBase.OnResize(e)' manually resize the caption width if in the visual designerIf Me.DesignMode Thencaption.Width = Me.WidthEnd IfEnd SubEnd Class

9。按F5编译保存
10。新建一个用户控件"testPane.vb"
11。加入代码:

Public Class testPaneInherits FotoVision.BasePaneEnd Class

12。将testPane控件拖到Form1.vb里面编译,就可以看到具有渐变色风格的标题的面板啦,多拖几个可以切换焦点。

[VB.net]绘制具有渐变颜色和防锯齿字体的标题相关推荐

  1. matplotlib绘制色阶渐变颜色条

    本例使用matplotlib库绘制了红.绿.蓝三原色的色阶渐变图.基本原理是用长而窄的纯色矩形来表示每个色阶,并将它们绘制在一张图中,效果如图所示. 效果图 1 实现思路 注意:matplotlib中 ...

  2. ai怎么渐变颜色_AI教程!渐变色噪点质感城堡场景插画绘制过程分享

    教程步骤 步骤 01 分析绘制思路,将插画分成背景+主体部分(云.山.树林.城堡.地面.湖面). 步骤 02 在AI里新建一个800*600px的画板 接着用矩形工具画一个与画板大小一样的矩形并填充渐 ...

  3. Python Matplotlib绘制渐变色柱状图(bar)并加边框和配置渐变颜色条(colorbar)

    热力图是数据分析的常用方法,通过色差.亮度来展示数据的差异.易于理解.目前,常见的是看数据表里多个特征两两的相关度热力图. 基于此思想,做出柱状热力图,用于展现单个特征针对整体的相关度,以此列出所有特 ...

  4. ai怎么渐变颜色_Ai渐变插画怎么丰富细节

    此次教程只需小伙伴对AI软件有基本的操作了解就可以完成,易上手容易理解. 止疼药瓶子 1.新建画布800X600,绘制止疼药瓶子轮廓 用矩形工具(W)绘制止疼药瓶子轮廓,圆角处用直接选择工具(A)选择 ...

  5. android自定义渐变色圆环,CircleShape渐变颜色圆环

    设计思路 通过自定义控件实现.将整个圆环拆分成一个个的小圆弧,每个小圆弧画笔的色值不一样,每个圆弧画笔的色值都是起始色值和终止色值的中间过渡色,由起始色值逐渐向终止色值靠拢,最后形成渐变颜色的圆环. ...

  6. 在VS中怎么用vb画矩形_怎样画颜色绚丽的插画?

    关于这种清新的插画,AI ,PS都可以做: 懒得动脑,我就临摹一张吧: 看完题主宝宝就明白了! (作者爸爸不要打我,我只是临摹一下啦!) https://www.pinterest.com/pin/5 ...

  7. Android Paint 绘制空心渐变圆角矩形

    Android Paint 绘制空心渐变圆角矩形 在onDraw()中使用Paint绘制空心的圆角矩形 代码 @Overrideprotected void onDraw(Canvas canvas) ...

  8. pyecharts画中国地图(省、市):如何调整渐变颜色、浏览器中大小、生成的HTML打开是空白无法显示的问题

    最近在做一个数模题,需要中国地图的数据可视化,了解到pyecharts,踩了一些坑,在此记录 ------------------------- 版本问题 现在网上大多数文章都是用的老版本,比如0.5 ...

  9. html5调颜色浏览器不显示,pyecharts画中国地图(省、市):如何调整渐变颜色、浏览器中大小、生成的HTML打开是空白无法显示的问题...

    最近在做一个数模题,需要中国地图的数据可视化,了解到pyecharts,踩了一些坑,在此记录 ------------------------- 版本问题 现在网上大多数文章都是用的老版本,比如0.5 ...

最新文章

  1. 《AI系统周刊》第5期:Cerebras发布可运行120万亿参数AI模型的CS-2芯片
  2. 素数问题是物质的几何学问题
  3. php: 通过key获取多维数组中的值
  4. java文件怎么建立关联_如何创建两个Java Web应用程序并相互关联jar依赖关系和其他文件?...
  5. 教科书上的LDA为什么长这样?
  6. python 计算协方差_python 线性代数:[12]求协方差矩阵
  7. Mysql 主从复制常用管理任务介绍
  8. python selenium headless chrome chromedriver 等安装
  9. python实现一个简单的项目_Python小项目四:实现简单的web服务器
  10. oracle复合字段,复合索引 选择频繁的字段,还是选择选择性低的字段 放在前面?...
  11. Modelsim-altera 仿真 顶层原理图的解决办法
  12. 1. 方程求根(二分法)
  13. 陆奇最新投资方向:机器人、生物科技、远程工作、云计算技术、新材料、新消费娱乐等,奇绩创坛春季创业营线上开营
  14. python在web可以开发吗_怎么用python进行web开发
  15. git gui怎么拉取项目代码_这些Git命令都不会,还是不要去面试了
  16. swagger2.2.2报错:relProviderPluginRegistry,linkDiscovererRegistry,entityLinksPluginRegistry
  17. iOS开发月报#3|201809
  18. 思科模拟配置文件服务器,思科模拟服务器配置教程
  19. 一键进入高通9008模式_高通3040芯片?游戏模式超低延迟?南卡lite pro全新升级!...
  20. 公文管理系统案例展示

热门文章

  1. ccsa安学网小程序_CCSA安学网安全题库完整
  2. 使用隐马尔科夫模型实现分词
  3. mysql使用union顺序混乱
  4. [css]我要用css画幅画(七) - 哆啦A梦
  5. 桌面图标有阴影,教给你怎么去掉
  6. springboot系列课程笔记-第一章-Spring Boot入门
  7. python中forward的参数_ip_forward参数对Linux内核转发影响分析
  8. Layabox开发微信小游戏好友排行榜功能流程
  9. Intelsat-29e卫星解体全损,威胁地球静止轨道安全
  10. 计算机应用 胡丹,正高级