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

728x90
반응형

TestProject.zip
다운로드

▶ MainForm.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

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

        #region Field

        /// <summary>
        /// X 최소값
        /// </summary>
        private const double X_MINIMUM = -2.2;

        /// <summary>
        /// X 최대값
        /// </summary>
        private const double X_MAXIMUM = 1;

        /// <summary>
        /// Y 최소값
        /// </summary>
        private const double Y_MINIMUM = -1.2;

        /// <summary>
        /// Y 최대값
        /// </summary>
        private const double Y_MAXIMUM = 1.2;


        /// <summary>
        /// 박스 그리기 여부
        /// </summary>
        private bool drawingBox;

        /// <summary>
        /// X 시작값
        /// </summary>
        private double xStart;
        
        /// <summary>
        /// Y 시작값
        /// </summary>
        private double yStart;
        
        /// <summary>
        /// X 현재값
        /// </summary>
        private double xCrrent;
        
        /// <summary>
        /// Y 현재값
        /// </summary>
        private double yCurrent;

        /// <summary>
        /// X 최소값
        /// </summary>
        private double xMinimum;
        
        /// <summary>
        /// X 최대값
        /// </summary>
        private double xMaximum;
        
        /// <summary>
        /// Y 최소값
        /// </summary>
        private double yMinimum;
        
        /// <summary>
        /// Y 최대값
        /// </summary>
        private double yMaximum;

        /// <summary>
        /// 비트맵
        /// </summary>
        private Bitmap bitmap;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 최대 반복 카운트 - MaximumIterationCount

        /// <summary>
        /// 최대 반복 카운트
        /// </summary>
        public int MaximumIterationCount { get; set; }

        #endregion
        #region Z1 실수부 - Z1Real

        /// <summary>
        /// Z1 실수부
        /// </summary>
        public double Z1Real { get; set; }
        
        #endregion
        #region Z1 허수부 - Z1Imaginary

        /// <summary>
        /// Z1 허수부
        /// </summary>
        public double Z1Imaginary { get; set; }
        
        #endregion
        #region Z2 실수부 - Z2Real

        /// <summary>
        /// Z2 실수부
        /// </summary>
        public double Z2Real { get; set; }
        
        #endregion
        #region Z2 허수부 - Z2Imaginary

        /// <summary>
        /// Z2 허수부
        /// </summary>
        public double Z2Imaginary { get; set; }

        #endregion
        #region 색상 리스트 - ColorList

        /// <summary>
        /// 색상 리스트
        /// </summary>
        public List<Color> ColorList { get; set; } = new List<Color>();

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

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

            #region 이벤트를 설정한다.

            Load                            += Form_Load;
            this.saveAsMenuItem.Click       += saveAsMenuItem_Click;
            this.scaleX2MenuItem.Click      += scaleMenuItem_Click;
            this.scaleX4MenuItem.Click      += scaleMenuItem_Click;
            this.scaleX8MenuItem.Click      += scaleMenuItem_Click;
            this.fullScaleMenuItem.Click    += fullScaleMenuItem_Click;
            this.refreshMenuItem.Click      += refreshMenuItem_Click;
            this.setOptionMenuItem.Click    += setOptionMenuItem_Click;
            this.canvasPictureBox.MouseDown += canvasPictureBox_MouseDown;
            this.canvasPictureBox.MouseMove += canvasPictureBox_MouseMove;
            this.canvasPictureBox.MouseUp   += canvasPictureBox_MouseUp;
            
            #endregion
        }

        #endregion

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

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

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

            Application.DoEvents();

            this.MaximumIterationCount = 64;

            ResetColorList();

            SettingForm form = new SettingForm();

            ColorList.Add(form.color40PictureBox.BackColor);
            ColorList.Add(form.color17PictureBox.BackColor);
            ColorList.Add(form.color18PictureBox.BackColor);
            ColorList.Add(form.color19PictureBox.BackColor);
            ColorList.Add(form.color20PictureBox.BackColor);
            ColorList.Add(form.color21PictureBox.BackColor);
            ColorList.Add(form.color22PictureBox.BackColor);
            ColorList.Add(form.color23PictureBox.BackColor);

            form.Close();

            this.fullScaleMenuItem.PerformClick();
        }

        #endregion
        #region 다른 이름으로 저장하기 메뉴 항목 클릭시 처리하기 - saveAsMenuItem_Click(sender, e)

        /// <summary>
        /// 다른 이름으로 저장하기 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void saveAsMenuItem_Click(object sender, EventArgs e)
        {
            if(this.saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filePath      = this.saveFileDialog.FileName;
                string fileExtension = filePath.Substring(filePath.LastIndexOf("."));

                switch(fileExtension)
                {
                    case ".bmp"  : this.bitmap.Save(filePath, ImageFormat.Bmp ); break;
                    case ".jpg"  :
                    case ".jpeg" : this.bitmap.Save(filePath, ImageFormat.Jpeg); break;
                    case ".gif"  : this.bitmap.Save(filePath, ImageFormat.Gif ); break;
                    case ".png"  : this.bitmap.Save(filePath, ImageFormat.Png ); break;
                    case ".tif"  :
                    case ".tiff" : this.bitmap.Save(filePath, ImageFormat.Tiff); break;
                    default      : this.bitmap.Save(filePath                  ); break;
                }
            }
        }

        #endregion
        #region 스케일 메뉴 항목 클릭시 처리하기 - scaleMenuItem_Click(sender, e)

        /// <summary>
        /// 스케일 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void scaleMenuItem_Click(object sender, EventArgs e)
        {
            MenuItem menuItem = sender as MenuItem;

            ScaleArea(int.Parse(menuItem.Tag.ToString()));
        }

        #endregion
        #region 전체 스케일 메뉴 항목 클릭시 처리하기 - fullScaleMenuItem_Click(sender, e)

        /// <summary>
        /// 전체 스케일 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void fullScaleMenuItem_Click(object sender, EventArgs e)
        {
            this.xMinimum = X_MINIMUM;
            this.xMaximum = X_MAXIMUM;
            this.yMinimum = Y_MINIMUM;
            this.yMaximum = Y_MAXIMUM;

            Cursor = Cursors.WaitCursor;

            Application.DoEvents();

            DrawMandelbrotFractal();

            Cursor = Cursors.Default;

            this.canvasPictureBox.Cursor = Cursors.Cross;
        }

        #endregion
        #region 새로 고침 메뉴 항목 클릭시 처리하기 - refreshMenuItem_Click(sender, e)

        /// <summary>
        /// 새로 고침 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void refreshMenuItem_Click(object sender, EventArgs e)
        {
            ScaleArea(1);
        }

        #endregion
        #region 옵션 설정하기 메뉴 항목 클릭시 처리하기 - setOptionMenuItem_Click(sender, e)

        /// <summary>
        /// 옵션 설정하기 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void setOptionMenuItem_Click(object sender, EventArgs e)
        {
            SettingForm form = new SettingForm();

            form.Initialize(this);

            form.StartPosition = FormStartPosition.CenterParent;

            form.ShowDialog(this);
        }

        #endregion
        #region 캔버스 픽처 박스 마우스 DOWN 처리하기 - canvasPictureBox_MouseDown(sender, e)

        /// <summary>
        /// 캔버스 픽처 박스 마우스 DOWN 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void canvasPictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            this.drawingBox = true;

            this.xStart   = e.X;
            this.yStart   = e.Y;
            this.xCrrent  = e.X;
            this.yCurrent = e.Y;
        }

        #endregion
        #region 캔버스 픽처 박스 마우스 이동시 처리하기 - canvasPictureBox_MouseMove(sender, e)

        /// <summary>
        /// 캔버스 픽처 박스 마우스 이동시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void canvasPictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            if(!this.drawingBox)
            {
                return;
            }

            this.xCrrent  = e.X;
            this.yCurrent = e.Y;
            
            Bitmap   newBitmap         = new Bitmap(this.bitmap);
            Graphics newBitmapGraphics = Graphics.FromImage(newBitmap);

            newBitmapGraphics.DrawRectangle
            (
                Pens.Yellow,
                (int)(Math.Min(this.xStart, this.xCrrent)),
                (int)(Math.Min(this.yStart, this.yCurrent)),
                (int)(Math.Abs(this.xStart - this.xCrrent)),
                (int)(Math.Abs(this.yStart - this.yCurrent))
            );

            this.canvasPictureBox.Image = newBitmap;
        }

        #endregion
        #region 캔버스 픽처 박스 마우스 UP 처리하기 - canvasPictureBox_MouseUp(sender, e)

        /// <summary>
        /// 캔버스 픽처 박스 마우스 UP 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void canvasPictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            if(!this.drawingBox)
            {
                return;
            }

            this.drawingBox = false;

            this.canvasPictureBox.Image = this.bitmap;

            this.xCrrent  = e.X;
            this.yCurrent = e.Y;

            double x1 = Math.Min(this.xStart, this.xCrrent);
            double x2 = Math.Max(this.xStart, this.xCrrent);

            if(x1 == x2)
            {
                x2 = x1 + 1;
            }

            double y1 = Math.Min(this.yStart, this.yCurrent);
            double y2 = Math.Max(this.yStart, this.yCurrent);

            if(y1 == y2)
            {
                y2 = y1 + 1;
            }

            double factor = (this.xMaximum - this.xMinimum) / this.canvasPictureBox.ClientSize.Width;

            this.xMaximum = this.xMinimum + x2 * factor;
            this.xMinimum = this.xMinimum + x1 * factor;

            factor = (this.yMaximum - this.yMinimum) / this.canvasPictureBox.ClientSize.Height;

            this.yMaximum = this.yMinimum + y2 * factor;
            this.yMinimum = this.yMinimum + y1 * factor;

            Cursor = Cursors.WaitCursor;

            Application.DoEvents();

            DrawMandelbrotFractal();

            Cursor = Cursors.Default;

            this.canvasPictureBox.Cursor = Cursors.Cross;
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Function
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 색상 리스트 리셋하기 - ResetColorList()

        /// <summary>
        /// 색상 리스트 리셋하기
        /// </summary>
        public void ResetColorList()
        {
            ColorList = new List<Color>();
        }

        #endregion

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

        #region 전망 조정하기 - AdjustAspect()

        /// <summary>
        /// 전망 조정하기
        /// </summary>
        private void AdjustAspect()
        {
            double height;
            double width;
            double middle;
            double aspectDesired          = (this.yMaximum - this.yMinimum) / (this.xMaximum - this.xMinimum);
            double canvasPictureBoxAspect = this.canvasPictureBox.ClientSize.Height / (double)this.canvasPictureBox.ClientSize.Width;

            if(aspectDesired > canvasPictureBoxAspect)
            {
                width  = (this.yMaximum - this.yMinimum) / canvasPictureBoxAspect;
                middle = (this.xMinimum + this.xMaximum) / 2;

                this.xMinimum = middle - width / 2;
                this.xMaximum = middle + width / 2;
            }
            else
            {
                height = (this.xMaximum - this.xMinimum) * canvasPictureBoxAspect;
                middle = (this.yMinimum + this.yMaximum) / 2;

                this.yMinimum = middle - height / 2;
                this.yMaximum = middle + height / 2;
            }
        }

        #endregion
        #region 망델브로 프랙탈 그리기 - DrawMandelbrotFractal()

        /// <summary>
        /// 망델브로 프랙탈 그리기
        /// </summary>
        private void DrawMandelbrotFractal()
        {
            const int MAXIMUM_MAG_SQUARED = 4;

            this.bitmap = new Bitmap(this.canvasPictureBox.ClientSize.Width, this.canvasPictureBox.ClientSize.Height);

            Graphics graphics = Graphics.FromImage(this.bitmap);

            graphics.Clear(this.canvasPictureBox.BackColor);

            this.canvasPictureBox.Image = this.bitmap;

            Application.DoEvents();

            AdjustAspect();

            int width  = this.canvasPictureBox.ClientRectangle.Width;
            int height = this.canvasPictureBox.ClientRectangle.Height;

            double deltaRealNumber      = (this.xMaximum - this.xMinimum) / (width  - 1);
            double deltaImaginaryNumber = (this.yMaximum - this.yMinimum) / (height - 1);

            int colorCount = ColorList.Count;

            double realNumber = this.xMinimum;

            for(int x = 0; x < width; x++)
            {
                double imaginaryNumber = this.yMinimum;

                for(int y = 0; y < height; y++)
                {
                    double z1Real      = Z1Real;
                    double z1Imaginary = Z1Imaginary;
                    double z2Real      = Z2Real;
                    double z2Imaginary = Z2Imaginary;

                    int color = 1;

                    while((color < MaximumIterationCount) && (z2Real + z2Imaginary < MAXIMUM_MAG_SQUARED))
                    {
                        z2Real      = z1Real * z1Real;
                        z2Imaginary = z1Imaginary * z1Imaginary;
                        z1Imaginary = 2 * z1Imaginary * z1Real + imaginaryNumber;
                        z1Real      = z2Real - z2Imaginary + realNumber;

                        color++;
                    }

                    this.bitmap.SetPixel(x, y, ColorList[color % colorCount]);

                    imaginaryNumber += deltaImaginaryNumber;
                }

                realNumber += deltaRealNumber;

                if(x % 10 == 0)
                {
                    this.canvasPictureBox.Refresh();
                }
            }

            Text = "망델브로 프랙탈(Mandelbrot Fractal) 그리기 : (" + this.xMinimum.ToString("0.000000") + ", "  +
                                                                      this.yMinimum.ToString("0.000000") + ")-(" +
                                                                      this.xMaximum.ToString("0.000000") + ", "  +
                                                                      this.yMaximum.ToString("0.000000") + ")";
        }

        #endregion
        #region 영역 스케일 처리하기 - ScaleArea(scaleFactor)

        /// <summary>
        /// 영역 스케일 처리하기
        /// </summary>
        /// <param name="scaleFactor">스케일 인자</param>
        private void ScaleArea(int scaleFactor)
        {
            double size = scaleFactor * (this.xMaximum - this.xMinimum);

            if(size > 3.2)
            {
                this.fullScaleMenuItem.PerformClick();

                return;
            }

            double middle = (this.xMinimum + this.xMaximum) / 2;

            this.xMinimum = middle - size / 2;
            this.xMaximum = middle + size / 2;

            size = scaleFactor * (this.yMaximum - this.yMinimum);

            if(size > 2.4)
            {
                this.fullScaleMenuItem.PerformClick();

                return;
            }

            middle = (this.yMinimum + this.yMaximum) / 2;

            this.yMinimum = middle - size / 2;
            this.yMaximum = middle + size / 2;

            Cursor = Cursors.WaitCursor;

            Application.DoEvents();

            DrawMandelbrotFractal();

            Cursor = Cursors.Default;

            this.canvasPictureBox.Cursor = Cursors.Cross;
        }

        #endregion
    }
}

 

▶ SettingForm.cs

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

namespace TestProject
{
    /// <summary>
    /// 설정 폼
    /// </summary>
    public partial class SettingForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 메인 폼
        /// </summary>
        private MainForm mainForm = null;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - SettingForm()

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

        #endregion

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

        #region 확인 버튼 클릭시 처리하기 - okButton_Click(sender, e)

        /// <summary>
        /// 확인 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void okButton_Click(object sender, EventArgs e)
        {
            this.mainForm.MaximumIterationCount = int.Parse(this.maximumIterationCountTextBox.Text);

            this.mainForm.Z1Real      = double.Parse(this.z1RealTextBox.Text     );
            this.mainForm.Z1Imaginary = double.Parse(this.z1ImaginaryTextBox.Text);
            this.mainForm.Z2Real      = double.Parse(this.z2RealTextBox.Text     );
            this.mainForm.Z2Imaginary = double.Parse(this.z2ImaginaryTextBox.Text);

            this.mainForm.ResetColorList();

            for(int i = 0; i < 48; i++)
            {
                Control control = GetControlByName(string.Format("color{0:d2}PictureBox", i));

                PictureBox pictureBox = control as PictureBox;

                if(pictureBox.BorderStyle == BorderStyle.Fixed3D)
                {
                    this.mainForm.ColorList.Add(pictureBox.BackColor);
                }
            }

            Close();
        }

        #endregion
        #region 취소 버튼 클릭시 처리하기 - cancelButton_Click(sender, e)

        /// <summary>
        /// 취소 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        #endregion

        #region 컬럼 버튼 클릭시 처리하기 - columnButton_Click(sender, e)

        /// <summary>
        /// 컬럼 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void columnButton_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;

            SelectColumn(int.Parse(button.Tag.ToString()));
        }

        #endregion
        #region 행 버튼 클릭시 처리하기 - rowButton_Click(sender, e)

        /// <summary>
        /// 행 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void rowButton_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;

            SelectRow(int.Parse(button.Tag.ToString()));        
        }

        #endregion
        #region 색상 픽처 박스 클릭시 처리하기 - colorPictureBox_Click(sender, e)

        /// <summary>
        /// 색상 픽처 박스 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void colorPictureBox_Click(object sender, EventArgs e)
        {
            PictureBox pictureBox = sender as PictureBox;

            if(pictureBox.BorderStyle == BorderStyle.Fixed3D)
            {
                pictureBox.BorderStyle = BorderStyle.None;
            }
            else
            {
                pictureBox.BorderStyle = BorderStyle.Fixed3D;
            }
        }

        #endregion

        #region 디폴트 버튼 클릭시 처리하기 - defaultButton_Click(sender, e)

        /// <summary>
        /// 디폴트 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void defaultButton_Click(object sender, EventArgs e)
        {
            this.noneButton.PerformClick();

            this.color40PictureBox.BorderStyle = BorderStyle.Fixed3D;
            this.color17PictureBox.BorderStyle = BorderStyle.Fixed3D;
            this.color18PictureBox.BorderStyle = BorderStyle.Fixed3D;
            this.color19PictureBox.BorderStyle = BorderStyle.Fixed3D;
            this.color20PictureBox.BorderStyle = BorderStyle.Fixed3D;
            this.color21PictureBox.BorderStyle = BorderStyle.Fixed3D;
            this.color22PictureBox.BorderStyle = BorderStyle.Fixed3D;
            this.color23PictureBox.BorderStyle = BorderStyle.Fixed3D;
        }

        #endregion
        #region 전체 선택 버튼 클릭시 처리하기 - allButton_Click(sender, e)

        /// <summary>
        /// 전체 선택 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void allButton_Click(object sender, EventArgs e)
        {
            foreach(Control control in Controls)
            {
                if(control is PictureBox)
                {
                    PictureBox pictureBox = control as PictureBox;

                    pictureBox.BorderStyle = BorderStyle.Fixed3D;
                }
            }
        }

        #endregion
        #region 전체 취소 버튼 클릭시 처리하기 - noneButton_Click(sender, e)

        /// <summary>
        /// 전체 취소 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void noneButton_Click(object sender, EventArgs e)
        {
            foreach(Control control in Controls)
            {
                if(control is PictureBox)
                {
                    PictureBox pictureBox = control as PictureBox;

                    pictureBox.BorderStyle = BorderStyle.None;
                }
            }
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Function
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 색상 설정하기 - SelectColor(color)

        /// <summary>
        /// 색상 설정하기
        /// </summary>
        /// <param name="color">색상</param>
        private void SelectColor(Color color)
        {
            foreach(Control control in Controls)
            {
                if(control is PictureBox)
                {
                    if(control.BackColor.Equals(color))
                    {
                        PictureBox pictureBox = control as PictureBox;

                        pictureBox.BorderStyle = BorderStyle.Fixed3D;

                        return;
                    }
                }
            }
        }

        #endregion
        #region 초기화 하기 - Initialize(mainForm)

        /// <summary>
        /// 초기화 하기
        /// </summary>
        /// <param name="mainForm">메인 폼</param>
        public void Initialize(MainForm mainForm)
        {
            this.mainForm = mainForm;

            this.maximumIterationCountTextBox.Text = this.mainForm.MaximumIterationCount.ToString("0");
            this.z1RealTextBox.Text                = this.mainForm.Z1Real.ToString("0.00");
            this.z1ImaginaryTextBox.Text           = this.mainForm.Z1Imaginary.ToString("0.00");
            this.z2RealTextBox.Text                = this.mainForm.Z2Real.ToString("0.00");
            this.z2ImaginaryTextBox.Text           = this.mainForm.Z2Imaginary.ToString("0.00");

            this.noneButton.PerformClick();

            for(int i = 0; i < this.mainForm.ColorList.Count; i++)
            {
                SelectColor(this.mainForm.ColorList[i]);
            }
        }

        #endregion
        #region 명칭으로 컨트롤 구하기 - GetControlByName(name)

        /// <summary>
        /// 명칭으로 컨트롤 구하기
        /// </summary>
        /// <param name="name">명칭</param>
        /// <returns>컨트롤</returns>
        private Control GetControlByName(string name)
        {
            foreach(Control control in Controls)
            {
                if(control.Name == name)
                {
                    return control;
                }
            }

            return null;
        }

        #endregion
        #region 픽처 박스 선택하기 - SelectPictureBox(name)

        /// <summary>
        /// 픽처 박스 선택하기
        /// </summary>
        /// <param name="name">명칭</param>
        private void SelectPictureBox(string name)
        {
            Control control = GetControlByName(name);

            PictureBox pictureBox = control as PictureBox;

            pictureBox.BorderStyle = BorderStyle.Fixed3D;
        }

        #endregion
        #region 컬럼 선택하기 - SelectColumn(index)

        /// <summary>
        /// 컬럼 선택하기
        /// </summary>
        /// <param name="index">인덱스</param>
        private void SelectColumn(int index)
        {
            this.noneButton.PerformClick();

            string pictureBoxName;

            for(int i = 0; i <= 5; i++)
            {
                pictureBoxName = string.Format("color{0:d2}PictureBox", (i * 8 + index));

                SelectPictureBox(pictureBoxName);
            }
        }

        #endregion
        #region 행 선택하기 - SelectRow(index)

        /// <summary>
        /// 행 선택하기
        /// </summary>
        /// <param name="index">인덱스</param>
        private void SelectRow(int index)
        {
            this.noneButton.PerformClick();

            string pictureBoxName;

            int firstNumber = index * 8;

            for(int i = 0; i <= 7; i++)
            {
                pictureBoxName = string.Format("color{0:d2}PictureBox", (i + firstNumber));

                SelectPictureBox(pictureBoxName);
            }
        }

        #endregion
    }
}
728x90
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요