我在form1类中具有以下代码:
private void pictureBox1_Click(object sender, EventArgs e)
{
if (radioButtonActor.Checked)
{
MouseEventArgs me = (MouseEventArgs)e;
Actor actor = new Actor(textBox1.Text, me.X, me.Y);
actor.DrawActor(pictureBox1.CreateGraphics());
}
else if (radioButtonUseCase.Checked)
{
MouseEventArgs me = (MouseEventArgs)e;
UseCase usecase = new UseCase(textBox1.Text, me.X, me.Y);
usecase.DrawUseCase(pictureBox1.CreateGraphics());
}
}
绘图剂和吸引酶酶方法只是名为Actor和Usecase的类中图形线的行。UI具有图像框和一些RadioButtons。根据检查哪个放射线布顿的不同方法,正在运行不同的方法,绘制不同的图片。
而不是在Form1类中使用此语句,而不是非常可维护的语句,我将如何检查选中哪个单选按钮?我想做这样的事情:
单击油漆表格>从一个名为编辑器>的新类中运行方法方法检查以查看检查哪个单选按钮>如果这里的语句决定下一步运行的方法。
所有建议都非常感谢!谢谢。
我相信您想在代码中的其他地方重新使用此逻辑。因此,您可以创建这样的课程。
static class MyDrawer
{
public static void ChecknDraw(RadioButton radioButtonActor,RadioButton radioButtonUseCase, TextBox textBox1, PictureBox pictureBox1, EventArgs e)
{
if (radioButtonActor.Checked)
{
MouseEventArgs me = (MouseEventArgs)e;
Actor actor = new Actor(textBox1.Text, me.X, me.Y);
actor.DrawActor(pictureBox1.CreateGraphics());
}
else if (radioButtonUseCase.Checked)
{
MouseEventArgs me = (MouseEventArgs)e;
UseCase usecase = new UseCase(textBox1.Text, me.X, me.Y);
usecase.DrawUseCase(pictureBox1.CreateGraphics());
}
}
}
但是,在看到您在ASP.NET中使用它的评论后,这将无法达到您的目的,因为控件(文本框,图片框等)完全不同,您将在那里没有图形对象或鼠标指针。甚至可以通过用最终值创建类而不是传递控制对象来管理这一点。有趣的部分是您的DrawActor
方法