获取用户输入的参数,然后绘制形状C#
我试图从用户那里获得输入,将x,y坐标设置为Dropellipse函数,当我硬编码这些值时,它会在屏幕上画一个圆,但当我尝试传递一个来自用户输入的int时,它不起作用 我正在尝试制作一个程序来响应用户的命令,例如,用户可以键入“绘制形状x y”。 当检测到一个空格时,字符串被拆分为一个数组获取用户输入的参数,然后绘制形状C#,c#,forms,geometry,draw,C#,Forms,Geometry,Draw,我试图从用户那里获得输入,将x,y坐标设置为Dropellipse函数,当我硬编码这些值时,它会在屏幕上画一个圆,但当我尝试传递一个来自用户输入的int时,它不起作用 我正在尝试制作一个程序来响应用户的命令,例如,用户可以键入“绘制形状x y”。 当检测到一个空格时,字符串被拆分为一个数组 public partial class Form1 : Form { String input; Bitmap drawOutput; String command, comman
public partial class Form1 : Form
{
String input;
Bitmap drawOutput;
String command, command2, command3;
int x, y;
public Form1()
{
InitializeComponent();
drawOutput = new Bitmap(OutputBox.Size.Width, OutputBox.Size.Height);
OutputBox.Image = drawOutput;
}
private void Form1_Load(object sender, EventArgs e)
{
Graphics g;
g = Graphics.FromImage(drawOutput);
Pen mypen = new Pen(Color.Black);
g.Clear(Color.White);
g.Dispose();
}
private void CMDBox_TextChanged(object sender, EventArgs e)
{
input = CMDBox.Text;
}
private void ExecuteBtn_Click(object sender, EventArgs e)
{
String[] spilt = input.Split(' ');
foreach (String words in spilt)
{
command = spilt[0];
command2 = spilt[1];
command3 = spilt[2];
x = Int32.Parse(command2);
y = Int32.Parse(command3);
Graphics g;
g = Graphics.FromImage(drawOutput);
Pen pen = new Pen(Color.Black, 5);
if (input == command)
{
g.DrawEllipse(pen, 0, 0, x, y);
OutputBox.Image = drawOutput;
g.Dispose();
}
}
}
}
有人能帮忙吗?嗯,问题到底是什么?如何使用用户选择的数字绘制形状?e、 g.用户可以键入draw 100。然后,x坐标和y坐标将设置为该坐标,然后在屏幕上绘制。只有在正确的情况下才能使用。
if(input==command)
中的硬编码总是返回false,因为command是输入的一部分……如果这是一个WinForm,而不是HTML表单,你需要一本书或教程,因为这不是如何绘制WinForm的。帮你自己一个忙,写出你想要实现的完整语法,也许是这样的:[画图|填充][rect | ellispe]x y w h颜色