본문 바로가기

.NET

C# GDI console 관련 예제

반응형










using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;// 추가
using System.Windows.Forms;// 추가

namespace ConsoleGDI_
{
class GDI_01 : Form   // 윈도우 폼을 쓸려면 폼 추가  ㅎㅎ
{
Button btn = null;
public GDI_01()
{
btn = new Button();
btn.Text = "검색";
btn.Location = new Point(10,10);
btn.Size = new Size(200,100);
// location + size 를 합친것  =>  btn.SetBounds(...) ;
btn.Click += new EventHandler(btn_Click);
this.Text = "GDI+ 예제 첫번째"; // 폼의 텍스트를 말한다
this.Controls.Add(btn);
}
static void Main(string[] args)
{
Application.Run(new GDI_01());
}
protected void btn_Click(object sender, EventArgs e)
{
MessageBox.Show("검색버튼을 클릭했습니다","확인");
}
}
}






protected void btn_Click(object sender, EventArgs e)
{
//MessageBox.Show("검색버튼을 클릭했습니다","확인");
//Graphics g = btn.CreateGraphics(); // 버튼 부분만 그래픽 작업을하겟다는뜻이다
Graphics g = this.CreateGraphics();
g.FillRectangle(new SolidBrush(Color.Blue), this.ClientRectangle); 

//g.FillRectangle(new SolidBrush(Color.Blue) ,btn.ClientRectangle);
g.Dispose();
}














//////////////////////////////////////////////////////////////////////////////////////


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;// 추가
using System.Windows.Forms;// 추가

namespace ConsoleGDI_
{
class GDI_01 : Form   // 윈도우 폼을 쓸려면 폼 추가  ㅎㅎ
{
Button btn = null;
public GDI_01()
{
btn = new Button();
btn.Text = "검색";
btn.Location = new Point(10,10);
btn.Size = new Size(200,100);
// location + size 를 합친것  =>  btn.SetBounds(...) ;
btn.Click += new EventHandler(btn_Click);
this.Text = "GDI+ 예제 첫번째"; // 폼의 텍스트를 말한다
this.Controls.Add(btn);
}
static void Main(string[] args)
{
Application.Run(new GDI_01());
}
protected void btn_Click(object sender, EventArgs e)
{
//MessageBox.Show("검색버튼을 클릭했습니다","확인");
//Graphics g = btn.CreateGraphics(); // 버튼 부분만 그래픽 작업을하겟다는뜻이다
Graphics g = this.CreateGraphics();
g.FillRectangle(new SolidBrush(Color.Blue), this.ClientRectangle); 
            //g.FillRectangle(new SolidBrush(Color.Blue) ,btn.ClientRectangle);
g.Dispose();
}
}
}


/////////////////////////////////////////////////////////////////////////////////////////////////