• 大小: 30KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-26
  • 语言: C#
  • 标签:

资源简介

c#自定义圆角panel,可设置圆角的弧度,可设置图片,并且有单击事件,自己可以再次修改源码。文件中已生成dll

资源截图

代码片段和文件信息

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

namespace ControlPanel
{
    [ToolboxBitmap(typeof(Panel))]
    [DefaultEvent(“PanelClick“)]
    public partial class PicturePanel : UserControl
    {
        public PicturePanel()
        {
            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;
        }
        public delegate void ClickHandle(object sender EventArgs e);
        public event ClickHandle PanelClick;
        private int radius;  // 圆角弧度

        /// 圆角弧度(0为不要圆角)
        [Browsable(true)]
        [Description(“圆角弧度(0为不要圆角)“)]
        public int Radius 
        {
            get
            {
                return radius;
            }
            set
            {
                if (value < 0) { radius = 0; }
                else { radius = value; }
                base.Refresh();
            }
        }

        private Image picture;
        [Description(“设置图片“)]
        public Image Picture
        {
            get { return picture; }
            set { picture = value; pictureBox1.Image = picture; Invalidate(); }
        }

        private PictureBoxSizeMode imageMode;
        [Description(“设置图片定位“)]
        public PictureBoxSizeMode ImageMode
        {
            get { return imageMode; }
            set { imageMode = value; pictureBox1.SizeMode = imageMode; Invalidate(); }
        }
        // 圆角代码
        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);
            }
            // -----------------------------------------------------------------------------------------------
  

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

     文件       9728  2014-02-20 21:11  ControlPanel\bin\Debug\ControlPanel.dll

     文件      19968  2014-02-20 21:11  ControlPanel\bin\Debug\ControlPanel.pdb

     文件       3265  2014-02-06 20:32  ControlPanel\ControlPanel.csproj

     文件        643  2014-02-20 21:11  ControlPanel\obj\Debug\ControlPanel.csproj.FileListAbsolute.txt

     文件       9728  2014-02-20 21:11  ControlPanel\obj\Debug\ControlPanel.dll

     文件      19968  2014-02-20 21:11  ControlPanel\obj\Debug\ControlPanel.pdb

     文件        180  2014-02-20 21:11  ControlPanel\obj\Debug\ControlPanel.PicturePanel.resources

     文件        180  2014-02-20 21:11  ControlPanel\obj\Debug\ControlPanel.Properties.Resources.resources

     文件       4440  2014-02-07 21:59  ControlPanel\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6008  2014-02-20 21:11  ControlPanel\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        218  2014-02-20 21:11  ControlPanel\obj\Debug\GenerateResource.read.1.tlog

     文件        538  2014-02-20 21:11  ControlPanel\obj\Debug\GenerateResource.write.1.tlog

     文件       4096  2014-02-06 20:31  ControlPanel\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       4515  2014-02-20 21:11  ControlPanel\PicturePanel.cs

     文件       2431  2014-02-20 21:09  ControlPanel\PicturePanel.Designer.cs

     文件       5817  2014-02-20 21:09  ControlPanel\PicturePanel.resx

     文件       1376  2014-02-06 20:14  ControlPanel\Properties\AssemblyInfo.cs

     文件       2863  2014-02-06 20:31  ControlPanel\Properties\Resources.Designer.cs

     文件       5817  2014-02-06 20:31  ControlPanel\Properties\Resources.resx

     目录          0  2014-02-06 20:31  ControlPanel\obj\Debug\TempPE

     目录          0  2014-02-20 21:11  ControlPanel\bin\Debug

     目录          0  2014-02-06 20:14  ControlPanel\bin\Release

     目录          0  2014-02-20 21:11  ControlPanel\obj\Debug

     目录          0  2014-02-06 20:14  ControlPanel\bin

     目录          0  2014-02-06 20:14  ControlPanel\obj

     目录          0  2014-02-06 20:31  ControlPanel\Properties

     目录          0  2014-02-06 20:15  ControlPanel

----------- ---------  ---------- -----  ----

               101779                    27



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

评论

共有 条评论