winform 窗體圓角設計


  網上看到的很多winform窗體圓角設計代碼都比較累贅,這里分享一個少量代碼就可以實現的圓角。主要運用了System.Drawing.Drawing2D。

  效果圖

  代碼如下。

        private void BeautiLoginForm_Paint(object sender, PaintEventArgs e)
        {
            Type(this, 25, 0.1);
        }
        private void Type(Control sender, int p_1, double p_2)
        {
            GraphicsPath oPath = new GraphicsPath();
            oPath.AddClosedCurve(new Point[] {
                new Point(0, sender.Height / p_1),
                new Point(sender.Width / p_1, 0),
                new Point(sender.Width - sender.Width / p_1, 0),
                new Point(sender.Width, sender.Height / p_1),
                new Point(sender.Width, sender.Height - sender.Height / p_1),
                new Point(sender.Width - sender.Width / p_1, sender.Height),
                new Point(sender.Width / p_1, sender.Height),
                new Point(0, sender.Height - sender.Height / p_1) }, (float)p_2);
            sender.Region = new Region(oPath);
        }

        private void BeautiLoginForm_Resize(object sender, EventArgs e)
        {
            Type(this, 25, 0.1);
        }

  代碼比較簡單,希望有所幫助。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM