C
C#7mo ago
hugheselite

✅ Help with creating shapes on a windows form app

I have created a windows form app to display shapes on a bitmap, my circle function works fine but my rectangle will work regardless of the text I put in, for example..
circle 40
circle 40
will draw a circle with a radius of 40 as it should
bingbong 30,20
bingbong 30,20
will still draw a rectangle even though the string is incorrect
else if (CommandSplit[0].Equals("rectangle") == true) ; /// RECTANGLE FUNCTION

{
try
{
ParameterSplit = CommandSplit[1].Split(",".ToCharArray());

int width = int.Parse(ParameterSplit[0]);
int height = int.Parse(ParameterSplit[1]);
ErrorHandlingWindow.Clear();

MyCanvass.DrawRectangle(width, height);
Refresh();
return;
}

catch (FormatException)
{
ErrorHandlingWindow.Text = FormatExceptionErrorMessage;
return;
}
catch (IndexOutOfRangeException)
{
ErrorHandlingWindow.Text = IndexOutOfRangeExceptionMessage;
return;

}
else if (CommandSplit[0].Equals("rectangle") == true) ; /// RECTANGLE FUNCTION

{
try
{
ParameterSplit = CommandSplit[1].Split(",".ToCharArray());

int width = int.Parse(ParameterSplit[0]);
int height = int.Parse(ParameterSplit[1]);
ErrorHandlingWindow.Clear();

MyCanvass.DrawRectangle(width, height);
Refresh();
return;
}

catch (FormatException)
{
ErrorHandlingWindow.Text = FormatExceptionErrorMessage;
return;
}
catch (IndexOutOfRangeException)
{
ErrorHandlingWindow.Text = IndexOutOfRangeExceptionMessage;
return;

}
11 Replies
hugheselite
hugheselite7mo ago
if (e.KeyCode == Keys.Enter)
{
String Command = SingleCommandLine.Text.Trim().ToLower();
CommandSplit = Command.Split(' ');
{

if (CommandSplit[0].Equals("circle") == true)

{
try
{
ParameterSplit = CommandSplit[1].Split(",".ToCharArray());

int radius = int.Parse(ParameterSplit[0]);
ErrorHandlingWindow.Clear();



MyCanvass.DrawCircle(radius);
Refresh();
System.Diagnostics.Debug.WriteLine(CommandSplit[0]);
System.Diagnostics.Debug.WriteLine(CommandSplit[1]);

return;


}
catch (FormatException)
{
ErrorHandlingWindow.Text = FormatExceptionErrorMessage;
return;
}
catch (IndexOutOfRangeException)
{
ErrorHandlingWindow.Text = IndexOutOfRangeExceptionMessage;
return;

}

}
if (e.KeyCode == Keys.Enter)
{
String Command = SingleCommandLine.Text.Trim().ToLower();
CommandSplit = Command.Split(' ');
{

if (CommandSplit[0].Equals("circle") == true)

{
try
{
ParameterSplit = CommandSplit[1].Split(",".ToCharArray());

int radius = int.Parse(ParameterSplit[0]);
ErrorHandlingWindow.Clear();



MyCanvass.DrawCircle(radius);
Refresh();
System.Diagnostics.Debug.WriteLine(CommandSplit[0]);
System.Diagnostics.Debug.WriteLine(CommandSplit[1]);

return;


}
catch (FormatException)
{
ErrorHandlingWindow.Text = FormatExceptionErrorMessage;
return;
}
catch (IndexOutOfRangeException)
{
ErrorHandlingWindow.Text = IndexOutOfRangeExceptionMessage;
return;

}

}
this is my circle function which works correctly
SinFluxx
SinFluxx7mo ago
Have you tried debugging to see what's going on / being passed through when your code's running? Might also help to see the full class
hugheselite
hugheselite7mo ago
I have and I honestly still can't figure it out :/ i'm going to paste the full class also, it had a character limit on disc one moment
SinFluxx
SinFluxx7mo ago
$paste
MODiX
MODiX7mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
hugheselite
hugheselite7mo ago
BlazeBin - dswcflnovpfd
A tool for sharing your source code with the world!
hugheselite
hugheselite7mo ago
https://paste.mod.gg/dszdybmvdwhz/0 this class contains my shape implementations, but I dont think thats the issue
BlazeBin - dszdybmvdwhz
A tool for sharing your source code with the world!
SinFluxx
SinFluxx7mo ago
else if (CommandSplit[0].Equals("rectangle") == true) ; should've spotted it from your initial message, you've got a semi colon at the end of your if statement
hugheselite
hugheselite7mo ago
yeah loooool i just posted my code to chat gpt first thing it said was ^^^ what a rookie lol ty very much can I upvote the reply or do anything useful?
SinFluxx
SinFluxx7mo ago
nah just $close if you're all sorted 🙂
MODiX
MODiX7mo ago
Use the /close command to mark a forum thread as answered