issam_dz
2011-11-26, 20:12
http://t1.gstatic.com/images?q=tbn:ANd9GcTjuwZ_hHaAiyWAINkZNy1wNkSNVpflo Uj8aFz6KKow5yhY72F5CHjNbjuXBQ
أقدم لكم اليوم برنامج بسيط لرسم محموعة أشكال لنتحصل على علم
الأمر يعتمد على بعض الحسابات الرياضية و استخدام بعض الدوال مثل الفرشاة brush و القلم pen
و كل هذا يدخل تحت ما يسمى استخدام GDI+ في الدوت نت
أول شيء ننشئ فورم عادي و نضيف لها الحدث Form1_Paint
ثم نضيف المكتبات التالية المهمة
و خاصة الأخير تين.
الآن يمكننا أن نكمل الباقي.
بالمناسبة رسمت علم الوم أ ليس حبا فيهم و لكن احتراما لهم و استحقارا لغابتنا غابة ميكي
و هذا سورس باقي الدول
using
System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace WindowsFormsApplication2
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
SetStyle(
ControlStyles.ResizeRedraw, true);
this.Width = 500;
this.Height = 310;
this.BackColor = Color.LightGreen;
}
privatevoid Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode =
SmoothingMode.AntiAlias;
DrawFlag(g, 20, 20,
this.Width - 50);
g.Dispose();
}
privatevoid DrawFlag(Graphics g, float x0, float y0, float width)
{
SolidBrush whiteBrush = newSolidBrush(Color.White);
SolidBrush blueBrush = newSolidBrush(Color.FromArgb(0, 0, 128));
SolidBrush redBrush = newSolidBrush(Color.Red);
float height = 10 * width / 19;
g.FillRectangle(whiteBrush, x0, y0, width, height);
for (int i = 0; i < 7; i++)
{
g.FillRectangle(redBrush, x0,
y0 + 2 * i * height / 13, width, height / 13);
}
RectangleF blueBox = newRectangleF(x0, y0,
2 * width / 5, 7 * height / 13);
g.FillRectangle(blueBrush, blueBox);
float offset = blueBox.Width / 40;
float dx = (blueBox.Width - 2 * offset) / 11;
float dy = (blueBox.Height - 2 * offset) / 9;
for (int j = 0; j < 9; j++)
{
float yc = y0 + offset + j * dy + dy / 2;
for (int i = 0; i < 11; i++)
{
float xc = x0 + offset + i * dx + dx / 2;
if ((i + j) % 2 == 0)
{
DrawStar(g,
this.Width/55, xc, yc);
}
}
}
whiteBrush.Dispose();
blueBrush.Dispose();
redBrush.Dispose();
}
privatevoid DrawStar(Graphics g, float r, float xc, float yc)
{
float sin36 = (float)Math.Sin(36.0 * Math.PI / 180.0);
float sin72 = (float)Math.Sin(72.0 * Math.PI / 180.0);
float cos36 = (float)Math.Cos(36.0 * Math.PI / 180.0);
float cos72 = (float)Math.Cos(72.0 * Math.PI / 180.0);
float r1 = r * cos72 / cos36;
PointF[] pts = newPointF[10];
pts[0] =
newPointF(xc, yc - r);
pts[1] =
newPointF(xc + r1 * sin36, yc - r1 * cos36);
pts[2] =
newPointF(xc + r * sin72, yc - r * cos72);
pts[3] =
newPointF(xc + r1 * sin72, yc + r1 * cos72);
pts[4] =
newPointF(xc + r * sin36, yc + r * cos36);
pts[5] =
newPointF(xc, yc + r1);
pts[6] =
newPointF(xc - r * sin36, yc + r * cos36);
pts[7] =
newPointF(xc - r1 * sin72, yc + r1 * cos72);
pts[8] =
newPointF(xc - r * sin72, yc - r * cos72);
pts[9] =
newPointF(xc - r1 * sin36, yc - r1 * cos36);
g.FillPolygon(
Brushes.White, pts);
}
}
}
هذه صورة البرنامج
http://img853.imageshack.us/img853/2971/capturetn.png
وهذا رابط تحميل المشروع كامل بالنسبة للملف التنفيذي موجود داخل Debug
http://www.mediafire.com/?abu9wl74s02d7e7
أقدم لكم اليوم برنامج بسيط لرسم محموعة أشكال لنتحصل على علم
الأمر يعتمد على بعض الحسابات الرياضية و استخدام بعض الدوال مثل الفرشاة brush و القلم pen
و كل هذا يدخل تحت ما يسمى استخدام GDI+ في الدوت نت
أول شيء ننشئ فورم عادي و نضيف لها الحدث Form1_Paint
ثم نضيف المكتبات التالية المهمة
و خاصة الأخير تين.
الآن يمكننا أن نكمل الباقي.
بالمناسبة رسمت علم الوم أ ليس حبا فيهم و لكن احتراما لهم و استحقارا لغابتنا غابة ميكي
و هذا سورس باقي الدول
using
System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace WindowsFormsApplication2
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
SetStyle(
ControlStyles.ResizeRedraw, true);
this.Width = 500;
this.Height = 310;
this.BackColor = Color.LightGreen;
}
privatevoid Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode =
SmoothingMode.AntiAlias;
DrawFlag(g, 20, 20,
this.Width - 50);
g.Dispose();
}
privatevoid DrawFlag(Graphics g, float x0, float y0, float width)
{
SolidBrush whiteBrush = newSolidBrush(Color.White);
SolidBrush blueBrush = newSolidBrush(Color.FromArgb(0, 0, 128));
SolidBrush redBrush = newSolidBrush(Color.Red);
float height = 10 * width / 19;
g.FillRectangle(whiteBrush, x0, y0, width, height);
for (int i = 0; i < 7; i++)
{
g.FillRectangle(redBrush, x0,
y0 + 2 * i * height / 13, width, height / 13);
}
RectangleF blueBox = newRectangleF(x0, y0,
2 * width / 5, 7 * height / 13);
g.FillRectangle(blueBrush, blueBox);
float offset = blueBox.Width / 40;
float dx = (blueBox.Width - 2 * offset) / 11;
float dy = (blueBox.Height - 2 * offset) / 9;
for (int j = 0; j < 9; j++)
{
float yc = y0 + offset + j * dy + dy / 2;
for (int i = 0; i < 11; i++)
{
float xc = x0 + offset + i * dx + dx / 2;
if ((i + j) % 2 == 0)
{
DrawStar(g,
this.Width/55, xc, yc);
}
}
}
whiteBrush.Dispose();
blueBrush.Dispose();
redBrush.Dispose();
}
privatevoid DrawStar(Graphics g, float r, float xc, float yc)
{
float sin36 = (float)Math.Sin(36.0 * Math.PI / 180.0);
float sin72 = (float)Math.Sin(72.0 * Math.PI / 180.0);
float cos36 = (float)Math.Cos(36.0 * Math.PI / 180.0);
float cos72 = (float)Math.Cos(72.0 * Math.PI / 180.0);
float r1 = r * cos72 / cos36;
PointF[] pts = newPointF[10];
pts[0] =
newPointF(xc, yc - r);
pts[1] =
newPointF(xc + r1 * sin36, yc - r1 * cos36);
pts[2] =
newPointF(xc + r * sin72, yc - r * cos72);
pts[3] =
newPointF(xc + r1 * sin72, yc + r1 * cos72);
pts[4] =
newPointF(xc + r * sin36, yc + r * cos36);
pts[5] =
newPointF(xc, yc + r1);
pts[6] =
newPointF(xc - r * sin36, yc + r * cos36);
pts[7] =
newPointF(xc - r1 * sin72, yc + r1 * cos72);
pts[8] =
newPointF(xc - r * sin72, yc - r * cos72);
pts[9] =
newPointF(xc - r1 * sin36, yc - r1 * cos36);
g.FillPolygon(
Brushes.White, pts);
}
}
}
هذه صورة البرنامج
http://img853.imageshack.us/img853/2971/capturetn.png
وهذا رابط تحميل المشروع كامل بالنسبة للملف التنفيذي موجود داخل Debug
http://www.mediafire.com/?abu9wl74s02d7e7