• 大小: 35KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-13
  • 语言: C#
  • 标签: 圆形按钮  

资源简介

c#实现圆形按钮控件

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace MyControl
{
    public partial class EllipseButton : UserControl
    {
        public EllipseButton()
        {
            InitializeComponent();

        }
        private string text;
      
        public override string Text
        {
            get { return text; }
            set { text = value; }
        }
       
        protected override void OnPaint(PaintEventArgs e)
        {
            
            Color BorderColor = Color.Black;
            Graphics g = e.Graphics;
 
            Rectangle rc = new Rectangle(0 0 this.ClientSize.Width this.ClientSize.Height);

            GraphicsPath path1 = new GraphicsPath();

            path1.AddEllipse(0 0 this.ClientSize.Width this.ClientSize.Height);

            Brush br1 = new SolidBrush(this.BackColor);        
            g.FillPath(br1 path1);//绘制按钮           
            Region rgn = new Region(path1); //将region赋值给button
        
            this.Region = rgn;
            if (this.Text != null)  // 绘制文本 
            {
                using (StringFormat f = new StringFormat())
                {
                    
                    f.Alignment = System.Drawing.StringAlignment.Center;// 水平居中对齐 
                    f.LineAlignment = System.Drawing.StringAlignment.Center;   // 垂直居中对齐 
                    f.FormatFlags = System.Drawing.StringFormatFlags.NoWrap;// 设置为单行文本 
                    SolidBrush fb = new SolidBrush(this.ForeColor); // 绘制文本 
                    e.Graphics.DrawString(this.Text this.Font fb new System.Drawing.RectangleF(0 0 this.ClientSize.Width this.ClientSize.Height) f);
                }
            }

        }
     
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      20480  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.exe

     文件      30208  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.pdb

     文件       5632  2005-11-11 22:25  WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe

     文件       1994  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\EllipseButton.cs

     文件       1223  2012-07-31 12:32  WindowsApplication1\WindowsApplication1\EllipseButton.Designer.cs

     文件        626  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\Form1.cs

     文件       1996  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\Form1.Designer.cs

     文件       5814  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\Form1.resx

     文件        842  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.csproj.GenerateResource.Cache

     文件      20480  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.exe

     文件        180  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.Form1.resources

     文件      30208  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.pdb

     文件        180  2012-07-31 12:31  WindowsApplication1\WindowsApplication1\obj\Debug\WindowsApplication1.Properties.Resources.resources

     文件       1024  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\obj\WindowsApplication1.csproj.FileListAbsolute.txt

     文件        478  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\Program.cs

     文件       1194  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\Properties\AssemblyInfo.cs

     文件       2894  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\Properties\Resources.Designer.cs

     文件       5612  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\Properties\Resources.resx

     文件       1104  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\Properties\Settings.Designer.cs

     文件        249  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\Properties\Settings.settings

     文件       3463  2012-07-31 12:31  WindowsApplication1\WindowsApplication1\WindowsApplication1.csproj

     文件        946  2012-07-31 12:28  WindowsApplication1\WindowsApplication1.sln

    ..A..H.     20992  2012-07-31 12:41  WindowsApplication1\WindowsApplication1.suo

     目录          0  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\obj\Debug\TempPE

     目录          0  2012-07-31 12:33  WindowsApplication1\WindowsApplication1\bin\Debug

     目录          0  2012-07-31 12:41  WindowsApplication1\WindowsApplication1\obj\Debug

     目录          0  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\bin

     目录          0  2012-07-31 12:31  WindowsApplication1\WindowsApplication1\obj

     目录          0  2012-07-31 12:28  WindowsApplication1\WindowsApplication1\Properties

     目录          0  2012-07-31 12:41  WindowsApplication1\WindowsApplication1

............此处省略4个文件信息

评论

共有 条评论