2024年5月7日发(作者:)
using System;
using c;
using entModel;
using ;
using g;
using ;
using ;
using ;
namespace WindowsFormsApplication2
{
publicpartialclassForm3 : Form
{
privateint i;
bool mousepress = false;
privatefloat sx1, ey1, sx2, ey2;
public Form3()
{
InitializeComponent();
}
privatevoid button1_Click(object sender, EventArgs e)
{
i = 1;
/*Pen myPen = new Pen();
Graphics gobj = Graphics();
ne(myPen, 30, 30, 120, 120); */
}
privatevoid button2_Click(object sender, EventArgs e)
{
i = 2;
/*Pen myPen = new Pen();
Graphics gobj = Graphics();
lipse(myPen, new Rectangle(30, 30, 100, 100));*/
}
privatevoid button3_Click(object sender, EventArgs e)
{
i = 3;
/* Form fr = new Form2();
alog();*/
}
privatevoid Form3_MouseDown(object sender, MouseEventArgs e)
{
sx1 = on.X;
ey1 = on.Y;
mousepress = true;
}
privatevoid Form3_MouseMove(object sender, MouseEventArgs e)
{
if (mousepress == true)
{
sx2 = on.X;
ey2 = on.Y;
using (Graphics g = Graphics())
{
();
if (i == 1)
{
ne(, sx1, ey1, sx2, ey2);
}
elseif (i == 2)
{
cmp();
}
else
{
dstring();
}
}
}
}
privatevoid Form3_MouseUp(object sender, MouseEventArgs e)
{
sx2 = on.X;
ey2 = on.Y;
Pen myPen = newPen();
Graphics g = Graphics();
if (i == 1)
{
ne(myPen, sx1, ey1, sx2, ey2);
}
elseif (i == 2)
{
cmp();
}
else
{
dstring();
}
mousepress = false;
}
protectedvoid cmp()
{
Graphics g = Graphics();
if (sx1 < sx2 && ey1 < ey2)
{
lipse(, sx1, ey1, sx2 - sx1, ey2 - ey1);
}
elseif (sx1 > sx2 && ey1 > ey2)
{
lipse(, sx2, ey2, sx1 - sx2, ey1 - ey2);
}
elseif (sx1 < sx2 && ey1 > ey2)
{
lipse(, sx1, ey2, sx2 - sx1, ey1 - ey2);
}
else
{
lipse(, sx2, ey1, sx1 - sx2, ey2 - ey1);
}
}
protectedvoid dstring()
{
Graphics g = Graphics();
string drawString = "使用drawstring方法";
Font myFont = newFont("黑体", 16);
Brush b = newSolidBrush();
StringFormat myFormat = newStringFormat();
ring(drawString, myFont, b, sx1, ey1, myFormat);
}
}
}
发布评论