첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ TextureBrush 클래스를 사용하는 방법을 보여준다.

TestProject.zip
다운로드

▶ MainForm.cs

using System;
using System.Drawing;
using System.Drawing.Text;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            #region 이벤트를 설정한다.

            Load += Form_Load;

            #endregion
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            Bitmap bitmap = new Bitmap(ClientSize.Width, ClientSize.Height);

            using(Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                graphics.Clear(BackColor);

                using(TextureBrush brush = new TextureBrush(Image.FromFile("Image\\ColoradoFlowers.png")))
                {
                    using(Font font = new Font("Times New Roman", 150, FontStyle.Bold))
                    {
                        graphics.DrawString("Flowers", font, brush, 0, 0);
                    }
                }

                using(TextureBrush brush = new TextureBrush(Image.FromFile("Image\\Smiley.png")))
                {
                    using(Font font = new Font("Times New Roman", 150, FontStyle.Bold))
                    {
                        graphics.DrawString("Smile!", font, brush, 75, 175);
                    }
                }
            }

            BackgroundImage = bitmap;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요