[C#]Box 그리기...
# 4) .Net ( Vs 2010 )/C#2010. 11. 29. 08:53
GDI+ 로 박스 그리고 그린객체 이동하기? 정도???
훈스에 올라온 질문에 답글한것임..
주석 없음!
public partial class Form1 : Form
{
Box b = new Box();
public Form1()
{
InitializeComponent();
b.Change += () => Invalidate();
}
int offset = 3;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Left)
{
b.X -= offset;
}
if (keyData == Keys.Right)
{
b.X += offset;
}
if (keyData == Keys.Up)
{
b.Y -= offset;
}
if (keyData == Keys.Down)
{
b.Y += offset;
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
b.Draw(e.Graphics);
}
}
public class Box
{
public delegate void __delegateOnChange();
Rectangle rct = new Rectangle();
public Box()
{
lineColor = Color.Red;
lineWidth = 2f;
rct.Width = 10;
rct.Height = 10;
}
public Size Size { get { return rct.Size; } set { rct.Size = value; OnChange(); } }
public Point Location { get { return rct.Location; } set { rct.Location = value; OnChange(); } }
public int X { get { return rct.X; } set { rct.X = value; OnChange(); } }
public int Y { get { return rct.Y; } set { rct.Y = value; OnChange(); } }
public int Width { get { return rct.Width; } set { rct.Width = value; OnChange(); } }
public int Height { get { return rct.Height; } set { rct.Height = value; OnChange(); } }
Color lineColor = Color.Red;
public Color LineColor { get { return lineColor; } set { lineColor = value; OnChange(); } }
float lineWidth = 2f;
public float LineWidth { get { return lineWidth; } set { lineWidth = value; OnChange(); } }
public event __delegateOnChange Change = null;
public virtual void OnChange()
{
if (Change != null) Change();
}
public void Draw(Graphics g)
{
g.DrawRectangle(new Pen(LineColor, LineWidth), this.rct);
}
}
훈스에 올라온 질문에 답글한것임..
주석 없음!
public partial class Form1 : Form
{
Box b = new Box();
public Form1()
{
InitializeComponent();
b.Change += () => Invalidate();
}
int offset = 3;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Left)
{
b.X -= offset;
}
if (keyData == Keys.Right)
{
b.X += offset;
}
if (keyData == Keys.Up)
{
b.Y -= offset;
}
if (keyData == Keys.Down)
{
b.Y += offset;
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
b.Draw(e.Graphics);
}
}
public class Box
{
public delegate void __delegateOnChange();
Rectangle rct = new Rectangle();
public Box()
{
lineColor = Color.Red;
lineWidth = 2f;
rct.Width = 10;
rct.Height = 10;
}
public Size Size { get { return rct.Size; } set { rct.Size = value; OnChange(); } }
public Point Location { get { return rct.Location; } set { rct.Location = value; OnChange(); } }
public int X { get { return rct.X; } set { rct.X = value; OnChange(); } }
public int Y { get { return rct.Y; } set { rct.Y = value; OnChange(); } }
public int Width { get { return rct.Width; } set { rct.Width = value; OnChange(); } }
public int Height { get { return rct.Height; } set { rct.Height = value; OnChange(); } }
Color lineColor = Color.Red;
public Color LineColor { get { return lineColor; } set { lineColor = value; OnChange(); } }
float lineWidth = 2f;
public float LineWidth { get { return lineWidth; } set { lineWidth = value; OnChange(); } }
public event __delegateOnChange Change = null;
public virtual void OnChange()
{
if (Change != null) Change();
}
public void Draw(Graphics g)
{
g.DrawRectangle(new Pen(LineColor, LineWidth), this.rct);
}
}
'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글
[IPC] Event 추가 ~~ (0) | 2011.05.14 |
---|---|
LINQ] 로또 구하기? (1) | 2011.04.25 |
[C#]TabControl에서 특정 TabPage를 안보이게 감추기.. (0) | 2010.11.26 |
[LINQ] 콤마 구분자 넣기? (0) | 2010.11.24 |
ChartFX 확장! (0) | 2010.10.05 |