資源簡介
為Winform中的Textbox添加圓角和邊框,圓角大小和邊框大小可以設置
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Drawing;
using?System.Drawing.Drawing2D;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.ComponentModel;
namespace?WindowsFormsApplicationGDI
{
????[ToolboxItem(true)]
????public?class?MyTextbox:TextBox
????{
????????///?
????????///?圓角值
????????///?
????????[Browsable(true)]
????????public?int?Radius?{?get;?set;?}?=?5;
????????public?int?BorderWidth?{?get;?set;?}?=?2;
????????public?Color?BorderColorForMouseHover?{?get;?set;?}?=?SystemColors.ButtonHighlight;
????????protected?override?void?onresize(EventArgs?e)
????????{
????????????base.onresize(e);
????????????this.Region=?Region?=?new?Region(GetRegionPath());
????????????
????????}
????????///?
????????///?獲取窗體有效區域路徑
????????///?
????????///?
????????private?GraphicsPath?GetRegionPath()
????????{
????????????var?graphicsPath?=?new?GraphicsPath();
????????????graphicsPath.StartFigure();
????????????graphicsPath.AddArc(this.ClientRectangle.Left?this.ClientRectangle.Top?Radius?*?2?Radius?*?2?180?90);
????????????graphicsPath.AddArc(this.ClientRectangle.Right?-?Radius?*?2?this.ClientRectangle.Top?Radius?*?2?Radius?*?2?270?90);
????????????graphicsPath.AddArc(this.ClientRectangle.Right?-?Radius?*?2?this.ClientRectangle.Bottom?-?Radius?*?2?Radius?*?2?Radius?*?2?0?90);
????????????graphicsPath.AddArc(this.ClientRectangle.Left?this.ClientRectangle.Bottom?-?Radius?*?2?Radius?*?2?Radius?*?2?90?90);
????????????graphicsPath.CloseFigure();
????????????return?graphicsPath;
????????}
????????///?
????????///?獲取重繪邊框的路徑
????????///?
????????///?
????????private?GraphicsPath?GetBorderPath()
????????{?????
????????????var?rec?=?new?Rectangle(ClientRectangle.X?+?1?ClientRectangle.Y?+?1?ClientRectangle.Width?-?2?ClientRectangle.Height?-?2);
????????????var?graphicsPath?=?new?GraphicsPath();
????????????graphicsPath.StartFigure();
????????????graphicsPath.AddArc(rec.Left?rec.Top?Radius?*?2?Radius?*?2?180?90);
????????????graphicsPath.AddArc(rec.
- 上一篇:C#控制系統聲音大小
- 下一篇:u3d拖拽旋轉縮放模型腳本
評論
共有 條評論