📄 form1.cs
字号:
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;
using System.Collections;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
namespace 第16次作业
{
public partial class Form1 : Form
{
public ArrayList ArrayLines = new ArrayList();
public ArrayList Arrayrec = new ArrayList();
public ArrayList Arrayell = new ArrayList();
public int x1, y1, x2, y2;
public Pen p1;
public Color c;
public float w;
int f;
public Form1()
{
InitializeComponent();
f = 0;
c = Color.Red;
txtbox1.Text = "2";
p1 = new Pen(Color.Black);
// p1.Color = c;
//p1.Width = 2;
}
public class cline
{
public float kuandu;
public Color col;
public int x1;
public int y1;
public int x2;
public int y2;
}
public class rectangle
{
public float kuandu;
public Color col;
public int x;
public int y;
public int width;
public int height;
}
public class ellipse
{
public float kuandu;
public Color col;
public int x;
public int y;
public int width;
public int height;
}
private void 画直线ToolStripMenuItem_Click(object sender, EventArgs e)
{
f=1;
}
private void 画椭圆ToolStripMenuItem_Click(object sender, EventArgs e)
{
f = 2;
}
private void 画矩形ToolStripMenuItem_Click(object sender, EventArgs e)
{
f = 3;
}
private void 不画图ToolStripMenuItem_Click(object sender, EventArgs e)
{
f = 0;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
statuslbl1.Text = "(" + e.X.ToString() +","+ e.Y.ToString() + ")";
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
x1 = e.X ; y1 = e.Y;
w = float.Parse (txtbox1.Text);
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
// Pen p1 = new Pen(Color. Black );
//c = Color.Red;
//txtbox1.Text = "2";
p1.Color = c;
p1.Width = w;
x2 = e.X; y2 = e.Y;
if (f == 1)
{
Graphics gdi = this.CreateGraphics();
gdi.DrawLine(p1 , new Point(x1, y1), new Point(x2, y2));
cline ob = new cline();
ob.x1 = x1; ob.y1 = y1;
ob.x2 = x2; ob.y2 = y2;
ob.col = p1.Color ;
ob.kuandu = float.Parse (txtbox1.Text);
ArrayLines.Add(ob);
}
if (f == 3)
{
int w1, h;
Graphics gdi = this.CreateGraphics();
w1 = System.Math.Abs(x1 - x2);
h = System.Math.Abs(y1 - y2);
//w1 = x2 - x1;
// h = y2 - y1;
if (x1 <= x2)
{
if (y1 < y2)
gdi.DrawRectangle(p1, x1, y1, w1, h);
else
gdi.DrawRectangle(p1, x1, y2, w1, h);
}
else
{
if (y1 < y2)
gdi.DrawRectangle(p1, x2, y1, w1, h);
else
gdi.DrawRectangle(p1, x2, y2, w1, h);
}
rectangle ob = new rectangle();
ob.x = x1; ob.y = y1;
ob.width = w1; ob.height = h;
ob.col = p1.Color;
ob.kuandu = float .Parse (txtbox1.Text);
Arrayrec.Add(ob);
}
if (f ==2)
{
int w1, h;
Graphics gdi = this.CreateGraphics();
//w1 = System.Math.Abs(x2 - x1);
// h = System.Math.Abs(y2- y1);
w1 = (x2 - x1);
h = (y2 - y1);
gdi.DrawEllipse(p1 , x1, y1, w1, h);
ellipse ob = new ellipse();
ob.x = x1; ob.y = y1;
ob.width = w1; ob.height = h;
ob.col = p1.Color;
ob.kuandu =float .Parse (txtbox1.Text);
Arrayell.Add(ob);
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
// Pen p1 = new Pen(Color .Black );
Graphics gdi = this.CreateGraphics();
cline ob;
for (int i = 0; i< ArrayLines.Count; i++)
{
ob = (cline )ArrayLines[i];
gdi.DrawLine(p1 , new Point(ob.x1, ob.y1), new Point(ob.x2, ob.y2));
}
rectangle ob1;
for (int i = 0; i < Arrayrec.Count; i++)
{
ob1 = (rectangle )Arrayrec[i];
gdi.DrawRectangle (p1 , ob1.x, ob1.y,ob1.width ,ob1.height );
}
ellipse ob2;
for (int i = 0; i < Arrayell.Count; i++)
{
ob2= (ellipse )Arrayell[i];
gdi.DrawEllipse (p1 , ob2.x, ob2.y, ob2.width, ob2.height);
}
}
private void 颜色ToolStripMenuItem_Click_1(object sender, EventArgs e)
{
ColorDialog dlg = new ColorDialog();
dlg.ShowDialog();
c = dlg.Color;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -