c#自定义圆角控件panel
来源:互联网 发布:歌词软件 乐 编辑:程序博客网 时间:2024/06/05 03:37
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace myControlLibrary
{
public partial class RoundPanel : System.Windows.Forms.Panel
{
public RoundPanel()
{
InitializeComponent();
this.Padding = new System.Windows.Forms.Padding(0, 0, 0, 0);
this.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0);
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
}
// 圆角
// ===============================================================================================
private int _Radius; // 圆角弧度
/// <summary>圆角弧度(0为不要圆角)</summary>
[Browsable(true)]
[Description("圆角弧度(0为不要圆角)")]
public int _setRoundRadius
{
get
{
return _Radius;
}
set
{
if (value < 0) { _Radius = 0; }
else { _Radius = value; }
base.Refresh();
}
}
// 圆角代码
public void Round(System.Drawing.Region region)
{
// -----------------------------------------------------------------------------------------------
// 已经是.net提供给我们的最容易的改窗体的属性了(以前要自己调API)
System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
int x = 0;
int y = 0;
int thisWidth = this.Width;
int thisHeight = this.Height;
int angle = _Radius;
if (angle > 0)
{
System.Drawing.Graphics g = CreateGraphics();
oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
oPath.CloseAllFigures();
Region = new System.Drawing.Region(oPath);
}
// -----------------------------------------------------------------------------------------------
else
{
oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
oPath.CloseAllFigures();
Region = new System.Drawing.Region(oPath);
}
}
// ===============================================================================================
public RoundPanel(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
{
base.OnPaint(pe);
Round(this.Region); // 圆角
}
protected override void OnResize(EventArgs eventargs)
{
base.OnResize(eventargs);
base.Refresh();
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
二
GraphicsPath path =
new
GraphicsPath();
path.AddArc(0, 0, 100, 200, 10, 270);
e.Graphics.DrawPath(
new
Pen(Color.Black,1),path);
0 0
- c#自定义圆角控件panel
- winform自定义panel控件
- WinFrom自定义控件–Panel扩展
- 重写panel控件,加自定义边框颜色
- 【转】WinFrom自定义控件–Panel扩展
- C# 清空panel中所有控件
- C# 为Panel控件增加双缓冲
- C#打印panel控件中内容
- Panel 控件概述(Windows 窗体)c#
- c#中panel控件有什么作用
- C#中容器控件GroupBox、Panel、TabControl
- C#控件 GroupBox和Panel的区别
- panel控件
- Panel控件
- 【转】用户自定义控件(含源代码)-圆角Panel
- 如何让C#的Panel控件可以拖动
- C#中容器控件GroupBox、Panel、TabControl的应用
- C#中解决Panel等控件闪烁的方法
- 浙大 PAT 乙级1059
- JavaWeb学习总结——JavaWEB_Servlet(尚硅谷_佟刚老师)
- CDH集成Kafka
- 基础算法-放苹果
- c++面试题2.0
- c#自定义圆角控件panel
- vlc打udp流
- 不同压缩算法比较
- Android Window 整理
- 总结8
- ETL利器Kettle实战应用解析系列二 【应用场景和实战DEMO下载】
- C++类和类的定义
- Oracle数据类型
- 【tool】基于主键的表在线重定义