می شود به کد زیر نگاهی بندازید که من برای دوارن چهار ضلعی از مرکز باید چه کار کنم.
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Point[] po = new Point[4];
int x1, y1, x2, y2;
int x01, y01, x02, y02;
public Form1()
{
InitializeComponent();
}
private void button1_Click_1(object sender, EventArgs e)
{
x01 = Convert.ToInt32(textBox1.Text );
y01 = Convert.ToInt32(textBox2 .Text );
x02 = Convert.ToInt32(textBox3.Text);
y02 = Convert.ToInt32(textBox4.Text);
Graphics g = pictureBox1.CreateGraphics();
Pen n_pen = new Pen(Color.Blue,2);
x1 = 125 + Convert.ToInt32(textBox1.Text);
y1 = 125 - Convert.ToInt32(textBox2.Text);
x2 = 125 + Convert.ToInt32(textBox3.Text);
y2 = 125 - Convert.ToInt32(textBox4.Text);
po[0].X = x1; po[0].Y = y1;
po[1].X = x2; po[1].Y = y1;
po[2].X = x1; po[2].Y = y2;
po[3].X = x2; po[3].Y = y2;
g.DrawLine(n_pen, po[0], po[1]);
g.DrawLine(n_pen, po[0], po[2]);
g.DrawLine(n_pen, po[1], po[3]);
g.DrawLine(n_pen, po[2], po[3]);
}
private void button2_Click(object sender, EventArgs e)
{
double re=Convert.ToDouble(textBox5.Text ) *Math.PI/180;
Graphics g = pictureBox1.CreateGraphics();
Pen n_pen = new Pen(Color.Brown, 1);
int x11, y11, x22, y22;
x11 =Convert.ToInt32((x01 * (float)Math.Cos(re) - y01 * (float)Math.Sin(re)));
y11 =Convert.ToInt32((x01 * (float)Math.Sin(re) + y01 * (float)Math.Cos(re)));
x22 = Convert.ToInt32((x02 * (float)Math.Cos(re) - y02 * (float)Math.Sin(re)));
y22 = Convert.ToInt32((x02 * (float)Math.Sin(re) + y02 * (float)Math.Cos(re)));
x1 = 125 + x11;
y1 = 125 - y11;
x2 = 125 + x22;
y2 = 125 - y22;
po[0].X = x1; po[0].Y = y1;
po[1].X = x2; po[1].Y = y1;
po[2].X = x1; po[2].Y = y2;
po[3].X = x2; po[3].Y = y2;
g.DrawLine(n_pen, po[0], po[1]);
g.DrawLine(n_pen, po[0], po[2]);
g.DrawLine(n_pen, po[1], po[3]);
g.DrawLine(n_pen, po[2], po[3]);
}
}
}
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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Point[] po = new Point[4];
int x1, y1, x2, y2;
int x01, y01, x02, y02;
public Form1()
{
InitializeComponent();
}
private void button1_Click_1(object sender, EventArgs e)
{
x01 = Convert.ToInt32(textBox1.Text );
y01 = Convert.ToInt32(textBox2 .Text );
x02 = Convert.ToInt32(textBox3.Text);
y02 = Convert.ToInt32(textBox4.Text);
Graphics g = pictureBox1.CreateGraphics();
Pen n_pen = new Pen(Color.Blue,2);
x1 = 125 + Convert.ToInt32(textBox1.Text);
y1 = 125 - Convert.ToInt32(textBox2.Text);
x2 = 125 + Convert.ToInt32(textBox3.Text);
y2 = 125 - Convert.ToInt32(textBox4.Text);
po[0].X = x1; po[0].Y = y1;
po[1].X = x2; po[1].Y = y1;
po[2].X = x1; po[2].Y = y2;
po[3].X = x2; po[3].Y = y2;
g.DrawLine(n_pen, po[0], po[1]);
g.DrawLine(n_pen, po[0], po[2]);
g.DrawLine(n_pen, po[1], po[3]);
g.DrawLine(n_pen, po[2], po[3]);
}
private void button2_Click(object sender, EventArgs e)
{
double re=Convert.ToDouble(textBox5.Text ) *Math.PI/180;
Graphics g = pictureBox1.CreateGraphics();
Pen n_pen = new Pen(Color.Brown, 1);
int x11, y11, x22, y22;
x11 =Convert.ToInt32((x01 * (float)Math.Cos(re) - y01 * (float)Math.Sin(re)));
y11 =Convert.ToInt32((x01 * (float)Math.Sin(re) + y01 * (float)Math.Cos(re)));
x22 = Convert.ToInt32((x02 * (float)Math.Cos(re) - y02 * (float)Math.Sin(re)));
y22 = Convert.ToInt32((x02 * (float)Math.Sin(re) + y02 * (float)Math.Cos(re)));
x1 = 125 + x11;
y1 = 125 - y11;
x2 = 125 + x22;
y2 = 125 - y22;
po[0].X = x1; po[0].Y = y1;
po[1].X = x2; po[1].Y = y1;
po[2].X = x1; po[2].Y = y2;
po[3].X = x2; po[3].Y = y2;
g.DrawLine(n_pen, po[0], po[1]);
g.DrawLine(n_pen, po[0], po[2]);
g.DrawLine(n_pen, po[1], po[3]);
g.DrawLine(n_pen, po[2], po[3]);
}
}
}
دیدگاه