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;
using System.Drawing.Drawing2D;
namespace Ex07
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// 버튼색 받아와서 단색 칠하기
private void ColorButton_Click(object sender, EventArgs e)
{
//panel1.BackColor = ((Button)sender).BackColor;
//CreateGraphics();
//Graphics grfx = panel1.CreateGraphics();//특정 컨트롤의 그리기 도수 반환
//grfx.FillRectangle(Brushes.Yellow, 0, 0, 100, 100);
Graphics grfx = panel1.CreateGraphics();
//SolidBrush 단색 칠할떄 사용
grfx.FillRectangle(new SolidBrush(((Button)sender).BackColor),
panel1.ClientRectangle); //컨트롤의 표시 가능 영역
grfx.Dispose();
}
// 문양 있는색 칠하기 Hatch Brush
private void button4_Click(object sender, EventArgs e)
{
Graphics grfx = panel1.CreateGraphics();
Random r = new Random();
int opt = r.Next(1, 6);
HatchBrush hb = null;
switch (opt)
{
case 1:
hb = new HatchBrush(HatchStyle.Wave, Color.Orange);
break;
case 2:
hb = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Orange);
break;
case 3:
hb = new HatchBrush(HatchStyle.Cross, Color.Orange);
break;
case 4:
hb = new HatchBrush(HatchStyle.DiagonalBrick, Color.Orange);
break;
case 5:
hb = new HatchBrush(HatchStyle.Vertical, Color.Orange);
break;
}
//grfx.FillRectangle(new HatchBrush(HatchStyle.Wave, Color.Orange), panel1.ClientRectangle);
grfx.FillRectangle(hb, panel1.ClientRectangle);
grfx.Dispose();
}
// 그라데이션 Gradient Brush
private void button5_Click(object sender, EventArgs e)
{
Graphics grfx = panel1.CreateGraphics();
Random r = new Random();
LinearGradientBrush brush = new LinearGradientBrush(
new Point(0, 0), //그라데이션 시작점
new Point(panel1.Width, panel1.Height), //그라데이션 종료점
Color.FromArgb(r.Next(256), r.Next(256), r.Next(256)), //시작색상
Color.FromArgb(r.Next(256), r.Next(256), r.Next(256))); //종료색상
grfx.FillRectangle(brush, panel1.ClientRectangle);
Graphics grfx2 = button5.CreateGraphics();
LinearGradientBrush brush2 = new LinearGradientBrush(
new Point(0, 0), //그라데이션 시작점
new Point(button5.Width, button5.Height),
Color.Olive,
Color.Navy);
grfx2.FillRectangle(brush2, button5.ClientRectangle);
grfx.Dispose();
grfx2.Dispose();
}
//그림불러오기 Texture Brush
private void button6_Click(object sender, EventArgs e)
{
Graphics grfx = panel1.CreateGraphics();
Image img = Image.FromFile("..\\..\\leena0.bmp");
TextureBrush tb = new TextureBrush(img);
grfx.FillRectangle(tb, panel1.ClientRectangle);
grfx.Dispose();
}
//새로운 윈폼을 열어 PictureBox 불러오기 New Windows
private void button7_Click(object sender, EventArgs e)
{
PictureForm form = new PictureForm();
form.ShowDialog();
}
}
}
'프로그램 > C# - Study' 카테고리의 다른 글
C# - Ex08 Client - Server (2ver) (1) | 2010.10.29 |
---|---|
C# - Ex08 Client - Server (1ver) (0) | 2010.10.29 |
C# - Ex06 - 그림판3 (0) | 2010.10.27 |
C# - Ex06 - 그림판2 (3) | 2010.10.27 |
C# - Ex06 - 그림판 (0) | 2010.10.27 |