■ 타원 버튼 그리기

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


TestProject.zip


MainForm.cs

 

 

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Windows.Forms;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : Form

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            ResizeRedraw = true;

 

            #region 이벤트를 설정한다.

 

            Paint += Form_Paint;

 

            #endregion

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        //////////////////////////////////////////////////////////////////////////////// Event

 

        #region 폼 페인트시 처리하기 - Form_Paint(sender, e)

 

        /// <summary>

        /// 폼 페인트시 처리하기

        /// </summary>

        /// <param name="sender">이벤트 발생자</param>

        /// <param name="e">이벤트 인자</param>

        private void Form_Paint(object sender, PaintEventArgs e)

        {

            e.Graphics.Clear(BackColor);

 

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

 

            Rectangle rectangle = new Rectangle

            (

                30,

                30,

                ClientSize.Width  - 60,

                ClientSize.Height - 60

            );

 

            using(LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.Lime, Color.DarkGreen, 225f))

            {

                e.Graphics.FillEllipse(brush, rectangle);

            }

 

            using(LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.Lime, Color.DarkGreen, 45f))

            {

                using(Pen pen = new Pen(brush, 20f))

                {

                    rectangle.X      += 10;

                    rectangle.Y      += 10;

                    rectangle.Width  -= 20;

                    rectangle.Height -= 20;

 

                    e.Graphics.DrawEllipse(pen, rectangle);

                }

            }

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker

댓글을 달아 주세요