问题描述
基本上,我正在将形状绘制到位图。用户可以在富文本字段中编写诸如Rectangle(200,100)或Square(100)之类的命令,然后形状就会出现在图片框中。
我正在尝试创建验证,以检查命令是否具有正确数量的参数以及命令是否正确编写。但是,当我运行代码时,我什么也得不到。问题出在第一个if语句上。
if (line.StartsWith("Rectangle("))
{
Match result = Regex.Match(line,@"(?<=\()(.*)(?=\))",RegexOptions.IgnoreCase); //Gets values inbetween quotation marks
if (result.Length > 5 && result.Length < 7) //Checks to see there is valid amount of parameters
{
System.Windows.Forms.MessageBox.Show("Parameter Length Invalid");
} else if (line.IndexOf('R') != -1) //Checks to see if the string value matches the command Rectangle.
{
System.Windows.Forms.MessageBox.Show("Parameter Command Incorrect");
} else if (IsNumeric(result.Value.Split(',')[0]) && IsNumeric(result.Value.Split(',')[1]))
{
Rectangle rectangle = new Rectangle(Color.Red,var1,var2,Convert.ToInt32(result.Value.Split(',')[0]),')[1]));
rectangle.draw(GFX);
}
}
有没有一种方法可以检查用户是否输入了Rectangle,并且在Rect之后是否有其他不同?
感谢任何建议,谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)