新文章 网摘 文章 随笔 日记

Winform自定义加载中控件


 

    /// <summary>
    /// 自定义加载中控件
    /// </summary>
    public class Loading : UserControl
    {
        private PictureBox _pictureBox1;
        public Loading()
        {
            InitializeComponent();
            _pictureBox1.Width = Width;
            _pictureBox1.Height = Height;
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Loading));
            this._pictureBox1 = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this._pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // _pictureBox1
            // 
            this._pictureBox1.BackColor = System.Drawing.Color.Transparent;
            this._pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("_pictureBox1.Image")));
            this._pictureBox1.Location = new System.Drawing.Point(0, 0);
            this._pictureBox1.Name = "_pictureBox1";
            this._pictureBox1.Size = new System.Drawing.Size(32, 32);
            this._pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
            this._pictureBox1.TabIndex = 0;
            this._pictureBox1.TabStop = false;
            // 
            // Loading
            // 
            this.BackColor = System.Drawing.Color.Transparent;
            this.Controls.Add(this._pictureBox1);
            this.Name = "Loading";
            this.Size = new System.Drawing.Size(34, 32);
            this.VisibleChanged += new System.EventHandler(this.Loading_VisibleChanged);
            ((System.ComponentModel.ISupportInitialize)(this._pictureBox1)).EndInit();
            this.ResumeLayout(false);

        }

        private void Loading_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                Left = (Parent.Width - Width) / 2;
                Top = (Parent.Height - Height) / 2;
            }
        }
    }

 

 

 

posted @ 2020-09-30 15:14  岭南春  阅读(212)  评论(0)    收藏  举报