Basically, I am drawing shapes to a bitmap. The user can write commands such as Rectangle(200,100) or Square(100) in a rich text field and the shape appears in the picturebox.
I'm trying to create validation which checks if the command has the right amount of parameters and if the command is written properly. However, when I run the code I get nothing back. The problem is on the first else if statement.
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]), Convert.ToInt32(result.Value.Split(',')[1]));
rectangle.draw(GFX);
}
}
Is there a way to check if the user typed in a Rectangle and if it's anything different after the Rect it should give an error.
Any advice is appreciated, thanks!
Aucun commentaire:
Enregistrer un commentaire