첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ 외곽선 텍스트 그리기

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


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.SmoothingMode = SmoothingMode.AntiAlias;

 

            GraphicsPath graphicsPath = new GraphicsPath(FillMode.Alternate);

 

            using(FontFamily fontFamily = new FontFamily("Times New Roman"))

            {

                using(StringFormat stringFormat = new StringFormat())

                {

                    stringFormat.Alignment     = StringAlignment.Center;

                    stringFormat.LineAlignment = StringAlignment.Center;

 

                    graphicsPath.AddString

                    (

                        "Outline Text",

                        fontFamily,

                        (int)FontStyle.Bold,

                        100,

                        ClientRectangle,

                        stringFormat

                    );

                }

            }

 

            e.Graphics.FillPath(Brushes.Blue, graphicsPath);

 

            using(Pen pen = new Pen(Color.Black, 3))

            {

                e.Graphics.DrawPath(pen, graphicsPath);

            }

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker

댓글을 달아 주세요