عندما تريد عمل اي رسمة على الشاشة يجبعليك أن تحدد نقتطين على الشاشة (إحداثيات)
سأقوم بعمل Class و أسميه Point يمثل احداثيات على الشاشة و قمت بعمله على شكل Class حتى يتسنى استخدامه في أي وقت و أي مكان داخل البرنامج ككل
Public Class Point {
Private int v1;
Private int y1;
//Contractor
Public Point(){
v1=y1=0;
}
Public Point (int xv1, int xy1){
setX(xv1);
setY(xy1);
}
Public void setX(int xv){
x1= (xv > 0) : xv ? 0;
}
Public void setY(int xy){
y1=(xy > 0) : xy ? 0;
}
Public int getX(){
returne x1;
}
Public int getY(){
retune y1;
}
}الآن سنقوم بالرسم في Form
namespace CsharpProg2
{
public partial class Form
{
private int x1, y1, x2, y2;
private String shape;
public Form()
{
InitializeComponent();
}
private void Form4_MouseDown(object sender, MouseEventArgs e)
{
x1 = e.x1;
y1 = e.y1;
}
private void Form4_MouseUp(object sender, MouseEventArgs e)
{
x2 = e.x1;
y2 = e.y1;
switch (shape)
{
case "Line":
drawLine();
break;
case "Rectangle":
drawRectangle();
break;
}
}
private void drawRectangle()
{
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.DrawRectangle(new Pen(colorDialog1.Color, int.Parse(thick.Text)),x1, y1, x2-x1, y2-y1);
formGraphics.Dispose();
}
private void drawLine()
{
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.DrawLine(new Pen(colorDialog1.Color,int.Parse(thick.Text)), x1, y1, x2, y2);
formGraphics.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
}
private void Form4_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 100; i++)
thick.Items.Add(i.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
shape = "Line";
}
private void button3_Click(object sender, EventArgs e)
{
shape = "Rectangle";
}
}
}بالنتظار ردودكم حتى نقوم بالتطوير على هذا المشروع الصغير
Software Engineer Mohammed