오늘의 C# 공부 : WinForm

////simpleWindow

//using System;

//namespace SimpleWindow
//{
//    class MainApp : System.Windows.Forms.Form
//    {
//        static void Main(string[] args)
//        {
//            System.Windows.Forms.Application.Run(new MainApp());
//        }
//    }
//}

////SimpleWindowClose
//using System;
//using System.Windows.Forms;

//namespace UsingApplication
//{
//    class MainApp : Form
//    {
//        static void Main(string[] args)
//        {
//            MainApp form = new MainApp();

//            form.Click += new EventHandler((sender, eventargs) =>
//            {
//                Console.WriteLine(“closing Window,,,”);
//                Application.Exit();
//            });

//            Console.WriteLine(“Starting Window Application…”);
//            Application.Run(form);

//            Console.WriteLine(“Exiting Window Application….”);

//        }

//    }
//}

////메시지 필터
//using System;
//using System.Windows.Forms;

//namespace MessageFilter
//{
//    class MessageFilter : IMessageFilter
//    {
//        public bool PreFilterMessage(ref Message m)
//        {
//            if (m.Msg == 0x0F || m.Msg == 0x200 || m.Msg == 0x113)
//                return false;

//            Console.WriteLine("{0} : {1} “, m.ToString(), m.Msg);

//            if (m.Msg == 0x201)
//                Application.Exit();

//            return true;
//        }
//    }

//    class MainApp : Form
//    {
//        static void Main(string[] args)
//        {
//            Application.AddMessageFilter(new MessageFilter());
//            Application.Run(new MainApp());
//        }
//    }
//}

////form Event

//using System;
//using System.Windows.Forms;

//namespace Formevent
//{

//    class MainApp : Form
//    {
//        public void MyMouseHandler(object sender, MouseEventArgs e)
//        {
//            Console.WriteLine(“Sender : {0} “, ((Form)sender).Text);
//            Console.WriteLine(“X:{0} , Y:{1}”, e.X, e.Y);
//            Console.WriteLine(“Button : {0} , Click : {1}”, e.Button, e.Clicks);
//            Console.WriteLine();
//        }

//        public MainApp(string title)
//        {
//            this.Text = title;
//            this.MouseDown +=new MouseEventHandler(MyMouseHandler);
//        }

//        static void Main(string[] args)
//        {
//            Application.Run(new MainApp(“Mouse Event Test”));
//        }
//    }

//}

////Form Size

//using System;
//using System.Windows.Forms;

//namespace FormSize
//{
//    class MainApp : Form
//    {
//        static void Main(string[] args)
//        {
//            MainApp form = new MainApp();
//            form.Width = 300;
//            form.Height = 200;

//            form.MouseDown += new MouseEventHandler(form_MouseDown);

//            Application.Run(form);
//        }

//        static void form_MouseDown(object sender, MouseEventArgs e)
//        {
//            Form form = (Form)sender;
//            int oldWidth = form.Width;
//            int oldHeigth = form.Height;

//            if (e.Button == MouseButtons.Left)
//            {
//                if (oldWidth < oldHeigth)
//                {
//                    form.Width = oldHeigth;
//                    form.Height = oldWidth;
//                }
//            }

//            else if (e.Button == MouseButtons.Right)
//            {
//                if (oldHeigth < oldWidth)
//                {
//                    form.Width = oldHeigth;
//                    form.Height = oldWidth;
                   
//                }
//            }

//            Console.WriteLine(“윈도우의 크기가 변경되었습니다”);
//            Console.WriteLine(“Width : {0} , Height {1} “, form.Width, form.Height);
//        }
//    }
//}

////백그라운드 이미지조절하기

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

//namespace FormBackground
//{
//    class MainApp : Form
//    {
//        Random rand;
//        public MainApp()
//        {
//            rand = new Random();

//            this.MouseWheel += new MouseEventHandler(MainApp_MouseWheel);
//            this.MouseDown += new MouseEventHandler(MainApp_MouseDown);
//        }

//        void MainApp_MouseDown(object sender, MouseEventArgs e)
//        {
//            if (e.Button == MouseButtons.Left)
//            {
//                Color oldcolor = this.BackColor;
//                //this.BackColor = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
//                this.BackColor = Color.FromArgb(255, 255, 0, 0);
               
//            }

//            else if (e.Button == MouseButtons.Right)
//            {
//                if (this.BackgroundImage != null)
//                {
//                    this.BackgroundImage = null;
//                    return;
//                }

//                string file = “sample.jpg”;

//                if (System.IO.File.Exists(file) == false)
//                    MessageBox.Show(“파일이 없ㅋ엉ㅋ”);
//                else
//                    this.BackgroundImage = Image.FromFile(file);
//            }
//        }

//        void MainApp_MouseWheel(object sender, MouseEventArgs e)
//        {
//            this.Opacity = this.Opacity + (e.Delta > 0 ? 0.1 : -0.1);
//            Console.WriteLine(“Opacity : {0}”, this.Opacity);
//        }

//        static void Main(string[] args)
//        {
//            Application.Run(new MainApp());
//        }
//    }
//}

////폼 스타일
//using System;
//using System.Windows.Forms;

//namespace FormStyle
//{
//    class MainApp : Form
//    {
//        static void Main(string[] args)
//        {
//            MainApp form = new MainApp();

//            form.Width = 400;
//            form.MouseDown += new MouseEventHandler(form_MouseDown);

//            Application.Run(form);
//        }

//        static void form_MouseDown(object sender, MouseEventArgs e)
//        {
//            Form form = (Form)sender;

//            if (e.Button == MouseButtons.Left)
//            {
//                form.MaximizeBox = true;
//                form.MinimizeBox = true;
//                form.Text = “최소 최대 오케이”;
//            }

//            else if (e.Button == MouseButtons.Right)
//            {
//                form.MaximizeBox = false;
//                form.MinimizeBox = false;
//                form.Text = “최소 최대 끔”;
//            }
//        }
//    }
//}

//폼과 컨트롤
using System;
using System.Windows.Forms;

namespace FormAndControl
{
    class MainApp : Form
    {
        static void Main(string[] args)
        {
            Button button = new Button();

            button.Text = “Click Me!”;
            button.Left = 100;
            button.Top = 50;

            button.Click += (object sender, EventArgs e) =>
                {
                    MessageBox.Show(“딸깍”);
                };

            MainApp form = new MainApp();
            form.Text = “Form & Control”;
            form.Height = 150;

            form.Controls.Add(button);

            Application.Run(form);
        }
    }
}

Hugo로 만듦
JimmyStack 테마 사용 중