WinForm"不错的Vista风格水晶按钮"控件使用(附:源码demo) 之配餐系统的开发

     做WinForm开发的朋友,应该都有这种感觉:vs自带的控件倒是不少,但美观的却很少 ——于是网上就有一些开源、收费或免费的不错的控件,像皮肤等控件库DotNetBar、饼状图控件pieChart(此控件的使用,可查看之前的一篇文章:WinForm"立体饼状图实现(附源码示例)" 之配餐系统的开发)....,(在之前的几篇介绍配餐系统开发的文章里,我主要是对一些功能的说明)而此文要跟大家分享的是"不错的Vista风格水晶按钮"控件的使用(界面美观性和用户体验的增强)。好了,直接切入正题,先看下此控件的运行效果:

     2011031921310069.jpg

       此按钮控件有以下几点值得说明一下:

      1.CornerRadius: ——此属性用来设置按钮两端的形状(椭圆或普通),属性值为数字,0:即普通按钮,>0的值则按钮的椭圆‘弯曲度’更大, 为20时即为上图中 绿色按钮,当值>20后效果就不太好,具体可下载demo后自行查看。

      2.按钮的BaseColor和ButtonColor同时设置,其效果类似于 渐变。

     

     此按钮控件 关键代码如下:


  
/// <summary>
/// Draws the outer border for the control
/// using the ButtonColor property.
/// </summary>
/// <param name="g"> The graphics object used in the paint event. </param>
private void DrawOuterStroke(Graphics g)
{
if ( this .ButtonStyle == Style.Flat && this .mButtonState == State.None){ return ;}
Rectangle r
= this .ClientRectangle;
r.Width
-= 1 ; r.Height -= 1 ;
using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius))
{
using (Pen p = new Pen( this .ButtonColor))
{
g.DrawPath(p, rr);
}
}
}

/// <summary>
/// Draws the inner border for the control
/// using the HighlightColor property.
/// </summary>
/// <param name="g"> The graphics object used in the paint event. </param>
private void DrawInnerStroke(Graphics g)
{
if ( this .ButtonStyle == Style.Flat && this .mButtonState == State.None){ return ;}
Rectangle r
= this .ClientRectangle;
r.X
++ ; r.Y ++ ;
r.Width
-= 3 ; r.Height -= 3 ;
using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius))
{
using (Pen p = new Pen( this .HighlightColor))
{
g.DrawPath(p, rr);
}
}
}

/// <summary>
/// Draws the background for the control
/// using the background image and the
/// BaseColor.
/// </summary>
/// <param name="g"> The graphics object used in the paint event. </param>
private void DrawBackground(Graphics g)
{
if ( this .ButtonStyle == Style.Flat && this .mButtonState == State.None){ return ;}
int alpha = (mButtonState == State.Pressed) ? 204 : 127 ;
Rectangle r
= this .ClientRectangle;
r.Width
-- ; r.Height -- ;
using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius))
{
using (SolidBrush sb = new SolidBrush( this .BaseColor))
{
g.FillPath(sb, rr);
}
SetClip(g);
if ( this .BackImage != null ){g.DrawImage( this .BackImage, this .ClientRectangle);}
g.ResetClip();
using (SolidBrush sb = new SolidBrush(Color.FromArgb(alpha, this .ButtonColor)))
{
g.FillPath(sb, rr);
}
}
}

/// <summary>
/// Draws the Highlight over the top of the
/// control using the HightlightColor.
/// </summary>
/// <param name="g"> The graphics object used in the paint event. </param>
private void DrawHighlight(Graphics g)
{
if ( this .ButtonStyle == Style.Flat && this .mButtonState == State.None){ return ;}
int alpha = (mButtonState == State.Pressed) ? 60 : 150 ;
Rectangle rect
= new Rectangle( 0 , 0 , this .Width, this .Height / 2 );
using (GraphicsPath r = RoundRect(rect, CornerRadius, CornerRadius, 0 , 0 ))
{
using (LinearGradientBrush lg = new LinearGradientBrush(r.GetBounds(),
Color.FromArgb(alpha,
this .HighlightColor),
Color.FromArgb(alpha
/ 3 , this .HighlightColor),
LinearGradientMode.Vertical))
{
g.FillPath(lg, r);
}
}
}

/// <summary>
/// Draws the glow for the button when the
/// mouse is inside the client area using
/// the GlowColor property.
/// </summary>
/// <param name="g"> The graphics object used in the paint event. </param>
private void DrawGlow(Graphics g)
{
if ( this .mButtonState == State.Pressed){ return ;}
SetClip(g);
using (GraphicsPath glow = new GraphicsPath())
{
glow.AddEllipse(
- 5 , this .Height / 2 - 10 , this .Width + 11 , this .Height + 11 );
using (PathGradientBrush gl = new PathGradientBrush(glow))
{
gl.CenterColor
= Color.FromArgb(mGlowAlpha, this .GlowColor);
gl.SurroundColors
= new Color[] {Color.FromArgb( 0 , this .GlowColor)};
g.FillPath(gl, glow);
}
}
g.ResetClip();
}

/// <summary>
/// Draws the text for the button.
/// </summary>
/// <param name="g"> The graphics object used in the paint event. </param>
private void DrawText(Graphics g)
{
StringFormat sf
= StringFormatAlignment( this .TextAlign);
Rectangle r
= new Rectangle( 8 , 8 , this .Width - 17 , this .Height - 17 );
g.DrawString(
this .ButtonText, this .Font, new SolidBrush( this .ForeColor),r,sf);
}

/// <summary>
/// Draws the image for the button
/// </summary>
/// <param name="g"> The graphics object used in the paint event. </param>
private void DrawImage(Graphics g)
{
if ( this .Image == null ) { return ;}
Rectangle r
= new Rectangle( 8 , 8 , this .ImageSize.Width, this .ImageSize.Height);
switch ( this .ImageAlign)
{
case ContentAlignment.TopCenter:
r
= new Rectangle( this .Width / 2 - this .ImageSize.Width / 2 , 8 , this .ImageSize.Width, this .ImageSize.Height);
break ;
case ContentAlignment.TopRight:
r
= new Rectangle( this .Width - 8 - this .ImageSize.Width, 8 , this .ImageSize.Width, this .ImageSize.Height);
break ;
case ContentAlignment.MiddleLeft:
r
= new Rectangle( 8 , this .Height / 2 - this .ImageSize.Height / 2 , this .ImageSize.Width, this .ImageSize.Height);
break ;
case ContentAlignment.MiddleCenter:
r
= new Rectangle( this .Width / 2 - this .ImageSize.Width / 2 , this .Height / 2 - this .ImageSize.Height / 2 , this .ImageSize.Width, this .ImageSize.Height);
break ;
case ContentAlignment.MiddleRight:
r
= new Rectangle( this .Width - 8 - this .ImageSize.Width, this .Height / 2 - this .ImageSize.Height / 2 , this .ImageSize.Width, this .ImageSize.Height);
break ;
case ContentAlignment.BottomLeft:
r
= new Rectangle( 8 , this .Height - 8 - this .ImageSize.Height, this .ImageSize.Width, this .ImageSize.Height);
break ;
case ContentAlignment.BottomCenter:
r
= new Rectangle( this .Width / 2 - this .ImageSize.Width / 2 , this .Height - 8 - this .ImageSize.Height, this .ImageSize.Width, this .ImageSize.Height);
break ;
case ContentAlignment.BottomRight:
r
= new Rectangle( this .Width - 8 - this .ImageSize.Width, this .Height - 8 - this .ImageSize.Height, this .ImageSize.Width, this .ImageSize.Height);
break ;
}
g.DrawImage(
this .Image,r);
}

private void SetClip(Graphics g)
{
Rectangle r
= this .ClientRectangle;
r.X
++ ; r.Y ++ ; r.Width -= 3 ; r.Height -= 3 ;
using (GraphicsPath rr = RoundRect(r, CornerRadius, CornerRadius, CornerRadius, CornerRadius))
{
g.SetClip(rr);
}
}

源码demo下载

创建C# WinForm水晶风格按钮 本文还有配套的精品资源,点击获取 简介:在C# WinForm应用开发中,为了提升用户界面的美观性并提供良好用户体验,本篇文章深入探讨了如何通过继承 Button 类并重写绘图方法来自定义实现水晶按钮控件,以及如何处理鼠标事件以实现动态效果。文章提供了创建透明背景和特殊渲染效果的按钮的详细步骤和代码示例,包括基本的按钮样式和进阶的动态视觉效果。此外,还涉及了如... 阅读详情

相关推荐

构建个性化水晶按钮体验:CrystalButton组件解析

本文还有配套的精品资源,点击获取 简介:CrystalButton为.NET平台提供了一个水晶样式的按钮组件,通过独特的设计和自定义能力,无需深入了解复杂图形设计即可创建专业视觉效果的按钮。组件支持Windows Forms和WPF技术,提供透明度和立体感的外观,实现状态管理和交互事件处理。它还支持样式和模板定制,以及皮肤化选项,以提升用户体验。开发者可以通过TestCry...

weixin_29069575的博客 1302

[转]WinForm"不错的Vista风格水晶按钮"控件使用(附:源码demo) 之配餐系统的开发...

http://www.cnblogs.com/know/archive/2011/03/19/1989093.html 做WinForm开发的朋友,应该都有这种感觉:vs自带的控件倒是不少,但美观的却很少 ——于是网上就有一些开源、收费或免费的不错的控件,像皮肤等控件库DotNetBar、饼状图控件pieChart(此控件的使用,可查看之前的一篇文章:WinForm"立体饼状图实现(附...

aptl84294的博客 211

.NET框架中自定义水晶按钮控件的设计与实现

NET自定义控件是扩展Windows Forms应用程序功能的一个强大方式,允许开发者创建具有特定功能的可重用组件。通过创建自定义控件,可以封装复杂逻辑,简化开发流程,使界面更加一致和易于管理。自定义控件不仅可以提高开发效率,还能够提供更好的用户体验,因为它可以针对特定需求进行优化。这在构建复杂的桌面应用程序时尤为有用,可以确保应用程序外观和行为的统一性。随着应用程序变得越来越复杂,标准控件可能无法满足所有的需求。使用自定义控件可以解决以下常见问题:界面统一性。

weixin_42476987的博客 942

PaddleOCR 多线程并发问题

服务暂时可以正常用,但是后续需要考虑多线程并发问题。

qq_45801780的博客 626

c# winform 自定义水晶按钮控件

代码 亲测可用喔 是c#的代码 不要下载错了

winform的水晶按钮

这是一个水晶按钮,背景颜色可变,浮动闪烁功能,很好看的。

【使用Flask基于PaddleOCR3.0开发一个接口 调用时报错RuntimeError: std::exception】

摘要:在使用PaddleOCR 3.0 CPU模式开发Flask接口时,发现调用存在交替失败现象。

qq_52148082的博客 1038

Winform中实现自定义水晶按钮控件示例代码.zip

Winform中实现自定义水晶按钮控件(附代码下载)

PaddleOCR CPU环境下多线程推理异常问题分析与解决方案

PaddleOCR CPU环境下多线程推理异常问题分析与解决方案 【免费下载链接】PaddleOCR 飞桨多语言OCR工具包(实用超轻量OCR系统,支持80+种语言识别,提供数据标注与合成工具,支持服务器、移动端、嵌入式及IoT设备端的训练与部署) Awesome multilingual OCR toolkits ba...

gitblog_01403的博客 1257

winForm 实现水晶按钮

winForm 实现水晶按钮,可用 winForm 实现水晶按钮,可用

C# 自定义控件 自定义Button控件 水晶按钮

C# 自定义控件 自定义Button控件 水晶按钮。其他控件的重写与此类似

Flask+PaddleOCR3.0多线程踩坑实录:如何用线程池解决RuntimeError异常

本文详细记录了在构建Flask+PaddleOCR 3.0高并发服务时,因Paddle Inference引擎非线程安全而引发的RuntimeError异常。通过深入分析问题根源,文章核心介绍了如何利用线程池技术,结合线程本地存储(TLS)为每个工作线程创建独立的OCR引擎实例,从而彻底解决多线程并发冲突,并提供了生产级部署的优化方案与配置建议。

bread的博客 479

C# winForm 创建水晶风格的按钮

C# winForm 创建水晶风格的按钮

[转]C# winForm 创建水晶风格的按钮

时下水晶风格比较流行,在天极网看到一篇制作水晶按钮控件的文章, 首先启动Visual Studio 2005,新建空白解决方案,我们取名为:TestCrystalButton, 然后在项目导航栏上右击鼠标添加新项目,为此解决方案添加新的C# Windows 控件库,取名为MyControls。 IDE会创建一个继承于UserControl名为UserControl1的类,修改代码使其继承...

weixin_34405332的博客 238

WPF做的水晶按钮,可应用到winform,很漂亮。

代码,很好用,很漂亮的按钮,是WPF做的,但是是应用到winform的,是自己做的控件。

2.设置Salesforce开发环境

Salesforce DX:salesforce Developer Experience (salesforce开发人员体验)LWC:Lightning Web Component(注意首字母是大写的,是一个概念,小写的话有组件本身的含义)CLI:Command Line Interface(命令行界面)version control system (VCS):版本控制系统。

nihaixiao的博客 2209
上一篇: last、locale、mesg、top
下一篇: Control.NamingContainer 属性
weixin_34088838
博客等级 码龄11年 5279粉丝 154原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值