본문 바로가기

   
Programming/Winform

GDI+ 구조체

반응형

C# : 프로그래밍 언어 모두 C# 이 기반

ADO.NET 기술 and 환경 GDI+ 그래픽을 사용함

ASP.NET 기술 and 환경 GDI+ 그래픽을 사용함

Winform 기술 and 환경

WPF 기술 and 환경

GDI+ : 그래픽 디바이스 인터페이스 기술 and 환경

1. Size 구조체

2. Point 구조체

3. Rectangle 구조체

4. Color 구조체

 

using System.Drawing;//GDI+ 네임스페이스

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;//GDI+ 네임스페이스

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Threading;

 

namespace WindowsForms01

{

       public partial class Struct01 : Form

       {

 

             public Struct01()

             {

                    InitializeComponent();

             }

 

             private void button1_Click(object sender, EventArgs e)

             {

                    //Size 구조체

                    // - width, height 정보

                    // - winform -> 컨트롤의 크기 지정 용도

                    // GDI 관련 구조체는 항상 클래스 만들듯이 만들어야한다.

 

                    //구조체도 프로퍼티를 만들수 있다.

                    //값형 Value 타입

                    //Size s;

                    //s.Width = 100;

                    //s.Height = 200;

 

 

                    Size s2 = new Size();//참조형(Reference Type)

                    s2.Width = 100;

                    s2.Height = 200;

 

                    //기존의 크기를 변경하고 내가지정한 사이즈로 바꾸자

                    this.button1.Size = s2;

                    //this.Size = s2;

             }

 

             private void button2_Click(object sender, EventArgs e)

             {

 

                    //this.button2.Size.Width = 100;

                    //this.button2.Size.Height = 200;

                    //1. 첫번째 방법

                    this.button2.Width = 100;

                    this.button2.Height = 200;

 

 

                    //2. 두번째 방법

                    this.button2.Size = new Size(100, 100);

             }

 

             private void button3_Click(object sender, EventArgs e)

             {

                    //Point 구조체

                    // - X, Y 멤버

                    // - 컨트롤의 위치 지정 역할

                    Point p1 = new Point();

                    p1.X = 0;

                    p1.Y = 0;

 

                    //기준점이 몇인지 알아야 한다.

                    Point p2 = new Point(200, 200);

                    this.button3.Location = p2;

 

                    this.Location = p1;

             }

 

             private void button4_Click(object sender, EventArgs e)

             {

                    //Rectangle 구조체

                    Rectangle rect = new Rectangle();

                    rect.Width = 100;

                    rect.Height = 100;

                    rect.X = 100;

                    rect.Y = 150;

 

                    //게임을 할떄 많이 쓰인다. 본체 총알 두개다 렉탱글 영역에 있다.

                    //rect.Intersect 인자값으로 하면 두개의 영역이 닿는지 판단 FALSE, TRUE를 판단

                    Graphics g = this.CreateGraphics();

                    g.DrawRectangle(Pens.Red, rect);

             }

 

             private void button5_Click(object sender, EventArgs e)

             {

                    //Color 구조체

                    //C#에서 색상

                    //1. Named Color

                    //2. ARGB(Alpah-투명도, Red, Green, Blue)

 

                    //Color c1 = new Color();

                    //c1.R = 0;

                    //c1.G = 255;

                    //c1.B = 0;

 

                    Color c1 = Color.Yellow;

 

                    //각 컨트롤의 배경색, 전경색(글자색상)

                    //Named Color 생성 방법

                    button5.BackColor = c1;

 

                    Color c2 = Color.Red;

                    button5.ForeColor = c2;

 

                    Color c3 = Color.FromArgb(125, 87, 0);

                    this.BackColor = c3;

 

                    //영문 네임명으로 색깔을 바꺼준다.

                    Color c4 = Color.FromName("Green");

                    this.BackColor = c4;

 

                    //테마 색깔 지정

                    //SystemColors.Control;

             }

 

             private void button6_Click(object sender, EventArgs e)

             {

                    ThreadStart ts = new ThreadStart(Test);

                    Thread th = new Thread(ts);

                    Random rnd = new Random();

                    //Thread th = new Thread(new ThreadStart(Test));

 

                    Color c = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));

                    this.BackColor = c;

                    th.IsBackground = true;

                    th.Start();

                   

             }

 

             private void Test()

             {

                    ThreadStart ts = new ThreadStart(Test);

                    Thread th = new Thread(ts);

 

                    for (int i = 0; i < 100000; i++)

                    {

                           Random rnd = new Random();

                           Color c = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));

                           this.BackColor = c;

                           //Thread th = new Thread(new ThreadStart(Test));

                           Thread.Sleep(100);

                    }

                   

             }

 

             private void button7_Click(object sender, EventArgs e)

             {

                    //300x400

                    //this.button7.Text = "하하";

                    //MessageBox.Show(this.button7.Text);

 

 

                    //Toggle Button

                    if (this.button7.Text == "On")

                    {

                           this.button7.Text = "Off";

                           this.Size = new Size(800, 500);

                    }

                    else

                    {

                           this.button7.Text = "On";

                           this.Size = new Size(300, 400);

                    }

             }

 

       }

}

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace WindowsForms01

{

       public partial class GDI_01 : Form

       {

             public GDI_01()

             {

                    InitializeComponent();

             }

 

             private void button1_Click(object sender, EventArgs e)

             {

                    //GDI+

                    // - Graphics 객체 주인공~ 그림 그리기

                    // - 도화지, 연필, , 물감, 지우개..

 

                    //Graphics g = new Graphics();

                    //1. 그리고자하는 객체의 CreateGraphics() 호출

                    //Graphics g = g에다가 생성하고

                    //button1.CreateGraphics  = button1에 그린다.

                    Graphics g = this.CreateGraphics();

                    //button1.CreateGraphics();

 

                    Pen pen = new Pen(Color.Red, 5.0F);

 

                    // : 외각선(직선, 도형, 곡선)

                    //draw = ,

                    // = width height 로 그린다.

                    //drawEllipse width height를 그린다.

                    g.DrawEllipse(pen, 100, 100, 200, 200);

             }

 

             private void GDI_01_Paint(object sender, PaintEventArgs e)

             {

                    //빨간색 원을 원래 있던데로..

                    //2. 폼에서만 사용

                    Graphics g = e.Graphics;

                    Pen pen = new Pen(Color.Red, 5.0F);

                    g.DrawEllipse(pen, 100, 100, 200, 200);

             }

       }

}

 

반응형