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

TestProject.zip
다운로드

▶ MainForm.cs

using System;
using System.Collections.Generic;
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();

            #region 이벤트를 설정한다.

            Load                                   += Form_Load;
            this.viewComboBox.SelectedIndexChanged += viewComboBox_SelectedIndexChanged;

            #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)
        {
            this.viewComboBox.SelectedIndex = 0;

            this.listView.SmallImageList = this.smallImageList;
            this.listView.LargeImageList = this.largeImageList;

            this.listView.MakeColumnHeaders
            (
                "제목"  , 230, HorizontalAlignment.Left,
                "URL"   , 220, HorizontalAlignment.Left,
                "ISBN"  , 130, HorizontalAlignment.Left,
                "이미지", 230, HorizontalAlignment.Left,
                "페이지", 50 , HorizontalAlignment.Right,
                "연도"  , 60 , HorizontalAlignment.Right
            );

            RectangleF smallRectangle = new RectangleF(0, 0, 32, 32);
            RectangleF largeRectangle = new RectangleF(3, 3, 58, 58);

            this.smallImageList.Images.Clear();
            this.largeImageList.Images.Clear();

            using(Pen smallPen = new Pen(Color.Blue, 2))
            {
                using(Pen largePen = new Pen(Color.Blue, 3))
                {
                    largePen.LineJoin = LineJoin.Round;

                    for(int i = 1; i <= 7; i++)
                    {
                        Bitmap smallBitmap = new Bitmap(32, 32);

                        using(Graphics smallGraphics = Graphics.FromImage(smallBitmap))
                        {
                            smallGraphics.SmoothingMode = SmoothingMode.AntiAlias;

                            smallGraphics.Clear(Color.Transparent);

                            DrawStar(smallGraphics, smallRectangle, i + 3, smallPen, Brushes.Yellow);

                            this.smallImageList.Images.Add(i.ToString(), smallBitmap);
                        }

                        Bitmap largeBitmap = new Bitmap(64, 64);

                        using(Graphics largeGraphics = Graphics.FromImage(largeBitmap))
                        {
                            largeGraphics.Clear(Color.Transparent);

                            largeGraphics.SmoothingMode = SmoothingMode.AntiAlias;

                            DrawStar(largeGraphics, largeRectangle, i + 3, largePen, Brushes.Yellow);

                            this.largeImageList.Images.Add(i.ToString(), largeBitmap);
                        }
                    }
                }
            }

            this.listView.AddRow
            (
                "1",
                "WPF 3d",
                "http://www.csharphelper.com/wpf3d.html",
                "978-1983905964",
                "http://www.csharphelper.com/wpf3d_350_429.jpg",
                "430",
                "2018"
            );

            this.listView.AddRow
            (
                "2",
                "The C# Helper Top 100",
                "http://www.csharphelper.com/top100.htm",
                "978-1546886716",
                "http://www.csharphelper.com/top100_350_433.jpg",
                "380",
                "2017"
            );

            this.listView.AddRow
            (
                "3",
                "Interview Puzzles Dissected",
                "http://www.csharphelper.com/puzzles.htm",
                "978-1539504887",
                "http://www.csharphelper.com/interview_puzzles_350_433.jpg",
                "300",
                "2016"
            );

            this.listView.AddRow
            (
                "4",
                "C# 24-Hour Trainer, 2e",
                "http://tinyurl.com/n2a5797",
                "978-1-119-06566-1",
                "http://www.csharphelper.com/csharp24hr_2e_79x100.jpg",
                "600",
                "2015"
            );

            this.listView.AddRow
            (
                "5",
                "Beginning Software Engineering",
                "http://tinyurl.com/pz7bavo",
                "978-1-118-96914-4",
                "http://tinyurl.com/y7zusrct",
                "480",
                "2015"
            );

            this.listView.AddRow
            (
                "6",
                "Essential Algorithms",
                "http://tinyurl.com/y9uqajqv",
                "978-1-118-61210-1",
                "http://tinyurl.com/y84d2jgp",
                "624",
                "2013"
            );

            this.listView.AddRow
            (
                "7",
                "Beginning Database Design Solutions",
                "http://www.vb-helper.com/db_design.htm",
                "978-0-470-38549-4",
                "http://www.vb-helper.com/db_design.jpg",
                "522",
                "2008"
            );
        }

        #endregion
        #region 뷰 콤보 박스 선택 인덱스 변경시 처리하기 - viewComboBox_SelectedIndexChanged(sender, e)

        /// <summary>
        /// 뷰 콤보 박스 선택 인덱스 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void viewComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch(this.viewComboBox.Text)
            {
                case "Large Icons" : this.listView.View = View.LargeIcon; break;
                case "Small Icons" : this.listView.View = View.SmallIcon; break;
                case "List"        : this.listView.View = View.List;      break;
                case "Tile"        : this.listView.View = View.Tile;      break;
                case "Details"     : this.listView.View = View.Details;   break;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 별 그리기 - DrawStar(graphics, rectangle, pointCount, pen, brush)

        /// <summary>
        /// 별 그리기
        /// </summary>
        /// <param name="graphics">그래픽스</param>
        /// <param name="rectangle">사각형</param>
        /// <param name="pointCount">포인트 카운트</param>
        /// <param name="pen">펜</param>
        /// <param name="brush">브러시</param>
        private void DrawStar(Graphics graphics, RectangleF rectangle, int pointCount, Pen pen, Brush brush)
        {
            float cx  = (rectangle.Left + rectangle.Right ) / 2f;
            float cy  = (rectangle.Top  + rectangle.Bottom) / 2f;
            float rx1 = rectangle.Width  / 2f - 1;
            float ry1 = rectangle.Height / 2f - 1;
            float rx2 = rx1 / 3f;
            float ry2 = ry1 / 3f;

            double theta  = -Math.PI / 2;
            double dtheta =  Math.PI / pointCount;

            List<PointF> pointList = new List<PointF>();

            for(int i = 0; i < pointCount; i++)
            {
                pointList.Add
                (
                    new PointF
                    (
                        (float)(cx + rx1 * Math.Cos(theta)),
                        (float)(cy + ry1 * Math.Sin(theta))
                    )
                );

                theta += dtheta;

                pointList.Add
                (
                    new PointF
                    (
                        (float)(cx + rx2 * Math.Cos(theta)),
                        (float)(cy + ry2 * Math.Sin(theta))
                    )
                );

                theta += dtheta;
            }

            PointF[] pointArray = pointList.ToArray();

            graphics.FillPolygon(brush, pointArray);

            graphics.DrawPolygon(pen, pointArray);
        }

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

댓글을 달아 주세요