PDA

View Full Version : سوال: رسم مربع و رنگ آمیزی درون



Milo_22
شنبه 16 آبان 1388, 10:42 صبح
با سلام به دوستان

یک سوال داشتم ! من یک برنامه می خوام بنویسم که باید از توابع گرافیکی در اون استفاده کنم اما بلد نیستم چطوری ...
قراره این برنامه یک مربع بکشه و داخلش رو به 2 قسمت تقسیم کنه و در هر قسمت سه تا رنگ خاص رو قرار بده !!!!
در حقیقت همون طیف رنگی ، رنگ های اصلی و فرعی .
حالا من شکلش رو میزارم اگر کسی راهنمایی بده ممنون می شم :لبخندساده:

Reza_Yarahmadi
شنبه 16 آبان 1388, 18:51 عصر
متوجه اعدادی که توی تصویر بود نشدم ولی ممکنه کد زیر کمکت کنه!
Graphics graph;
private void Form1_Load(object sender, EventArgs e)
{
graph = this.CreateGraphics();
}

private void button1_Click(object sender, EventArgs e)
{
int x1 = 100, x2 = 250, y1 = 100, y2 = 250;
Pen p = new Pen(Color.Red, 2);
Brush b = p.Brush;
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

graph.DrawLine(p, x1, y1, x2, y1);
graph.DrawLine(p, x1, y1, x1, y2);
graph.DrawLine(p, x2, y2, x2, y1);
graph.DrawLine(p, x2, y2, x1, y2);

graph.DrawLine(new Pen(Color.Black, 2), x1, y2, x2, y1);

path.AddLines((new Point[] { new Point(100, 100), new Point(150, 100), new Point(100, 150) }));
p.Color = Color.Green;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(150, 100), new Point(100, 150), new Point(100, 200), new Point(200, 100) }));
p.Color = Color.White;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(200, 100), new Point(100, 200), new Point(100, 250), new Point(250, 100) }));
p.Color = Color.Red;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(250, 100), new Point(100, 250), new Point(150, 250), new Point(250, 150) }));
p.Color = Color.Blue;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(250, 150), new Point(150, 250), new Point(200, 250), new Point(250, 200) }));
p.Color = Color.Yellow;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(200, 250), new Point(250, 200), new Point(250, 250) }));
p.Color = Color.Black;
b = p.Brush;
graph.FillPath(b, path);
}

Milo_22
شنبه 16 آبان 1388, 20:34 عصر
متوجه اعدادی که توی تصویر بود نشدم ولی ممکنه کد زیر کمکت کنه!
Graphics graph;
private void Form1_Load(object sender, EventArgs e)
{
graph = this.CreateGraphics();
}

private void button1_Click(object sender, EventArgs e)
{
int x1 = 100, x2 = 250, y1 = 100, y2 = 250;
Pen p = new Pen(Color.Red, 2);
Brush b = p.Brush;
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

graph.DrawLine(p, x1, y1, x2, y1);
graph.DrawLine(p, x1, y1, x1, y2);
graph.DrawLine(p, x2, y2, x2, y1);
graph.DrawLine(p, x2, y2, x1, y2);

graph.DrawLine(new Pen(Color.Black, 2), x1, y2, x2, y1);

path.AddLines((new Point[] { new Point(100, 100), new Point(150, 100), new Point(100, 150) }));
p.Color = Color.Green;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(150, 100), new Point(100, 150), new Point(100, 200), new Point(200, 100) }));
p.Color = Color.White;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(200, 100), new Point(100, 200), new Point(100, 250), new Point(250, 100) }));
p.Color = Color.Red;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(250, 100), new Point(100, 250), new Point(150, 250), new Point(250, 150) }));
p.Color = Color.Blue;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(250, 150), new Point(150, 250), new Point(200, 250), new Point(250, 200) }));
p.Color = Color.Yellow;
b = p.Brush;
graph.FillPath(b, path);

path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLines((new Point[] { new Point(200, 250), new Point(250, 200), new Point(250, 250) }));
p.Color = Color.Black;
b = p.Brush;
graph.FillPath(b, path);
}


ممنون خیلی زیاد
راستش خودم هم نمی دونم استادم واسه چی اون اعداد رو گذاشته بود ، اما مثله اینکه می خواد مختصات هر کدوم از اون قسمتهای رنگی رو نمایش بده