943,907 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 4145
  • C# RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Sep 27th, 2009
1

Re: direct robot

Just as any control a Panel has a Validating and Validated event, but IMO they are of not much use here. I should check the limits in every go button test if you would pass 100 or -100 in a separate method. This passing would depend on the direction so you could use a switch statement. Coming to think of it, you could probably do this in the Move method of your robot!
The location property of your robot contains the REAL Panel coordinates. When you Draw you shift these by adding half width and height so that 0,0 is in the middle of the Panel.
Now to show these in the position Label you have to substract half width and height. For the Y coordinate you also have to change sign!
The attached doc will make it clearer I hope.
Now for your border testing you could use both, it is up to you which you prefer. Succes.
Attached Files
File Type: doc panel coordinates.doc (27.0 KB, 35 views)
Last edited by ddanbe; Sep 27th, 2009 at 5:12 pm.
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Sep 27th, 2009
0

Re: direct robot

Click to Expand / Collapse  Quote originally posted by ddanbe ...
Just as any control a Panel has a Validating and Validated event, but IMO they are of not much use here. I should check the limits in every go button test if you would pass 100 or -100 in a separate method. This passing would depend on the direction so you could use a switch statement. Coming to think of it, you could probably do this in the Move method of your robot!
The location property of your robot contains the REAL Panel coordinates. When you Draw you shift these by adding half width and height so that 0,0 is in the middle of the Panel.
Now to show these in the position Label you have to substract half width and height. For the Y coordinate you also have to change sign!
The attached doc will make it clearer I hope.
Now for your border testing you could use both, it is up to you which you prefer. Succes.
I understand the real and fiction values of the panel. The problem I'm running into is I don't understand if I should use a:
C# Syntax (Toggle Plain Text)
  1. get
  2. {
  3. if (location.X > 100 && location.Y > -100)
  4. {
  5. throw new ArgumentException("You can't do that!");
  6. }
in the robot.cs or for the go1\10 buttons.

The book shows how to through an argument exception, but not for something like moving an object more for an indexer that validates data and throws an argument.
Or if I just throw an arguementExcept with try if else finally?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
EvilLinux is offline Offline
77 posts
since Sep 2009
Sep 27th, 2009
1

Re: direct robot

Why not make your own robotexception class?
c# Syntax (Toggle Plain Text)
  1. class RobotException : Exception
  2. {
  3. public string robotstr;
  4. public RobotException(string message)
  5. : base(message)
  6. {
  7. robotstr = message;
  8. }
  9. }
Use it:
c# Syntax (Toggle Plain Text)
  1. try
  2. {
  3. //something went wrong so throw exception
  4. throw new RobotException("no no");
  5. }
  6. catch (RobotException ex)
  7. {
  8. MessageBox.Show(ex.robotstr);
  9. }
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Sep 27th, 2009
0

Re: direct robot

form:
C# Syntax (Toggle Plain Text)
  1. private void go10Btn_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. throw new robotexception("You can't go that far; limited to 100units of movement");
  6. }
  7. catch (robotexception ex)
  8. {
  9. MessageBox.Show(ex.robotstr);
  10. }
  11. //Go 10.
  12. myRobot.Move(10);
  13. myRobot.Draw(robotpanel);
  14. //Update location info.
  15. robotlocationLlb.Text = myRobot.location.ToString();
  16.  
  17.  
  18.  
  19. }
robot.cs:
C# Syntax (Toggle Plain Text)
  1. class robotexception : Exception
  2. {
  3. public string robotstring;
  4. public robotexception(string message)
  5. : base(message)
  6. {
  7. robotstring = message;
  8. }
  9. }

Nope my stuff still isn't working, but I'm going to try to just work on getting something to at least validate if it goes over 100 and I'd be happy lol
Last edited by EvilLinux; Sep 27th, 2009 at 7:41 pm.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
EvilLinux is offline Offline
77 posts
since Sep 2009
Sep 27th, 2009
0

Re: direct robot

Click to Expand / Collapse  Quote originally posted by EvilLinux ...
form:
C# Syntax (Toggle Plain Text)
  1. private void go10Btn_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. throw new robotexception("You can't go that far; limited to 100units of movement");
  6. }
  7. catch (robotexception ex)
  8. {
  9. MessageBox.Show(ex.robotstr);
  10. }
  11. //Go 10.
  12. myRobot.Move(10);
  13. myRobot.Draw(robotpanel);
  14. //Update location info.
  15. robotlocationLlb.Text = myRobot.location.ToString();
  16.  
  17.  
  18.  
  19. }
robot.cs:
C# Syntax (Toggle Plain Text)
  1. class robotexception : Exception
  2. {
  3. public string robotstring;
  4. public robotexception(string message)
  5. : base(message)
  6. {
  7. robotstring = message;
  8. }
  9. }

Nope my stuff still isn't working, but I'm going to try to just work on getting something to at least validate if it goes over 100 and I'd be happy lol
Been playing with for a while and just keep getting a namespace error about it. I would normally think the validation is easier, but everything I've tired to do to get this retarded project to show message once X or Y hits 100 or -100 doesn't work. (this proves me I'm not going to be a programmer in life lol).
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
EvilLinux is offline Offline
77 posts
since Sep 2009
Sep 27th, 2009
0

Re: direct robot

My friend took one look at my code and said:
"your putting your if \ else in the wrong place"
I put it at the location = P... And freaking work. I drove myself nuts for nothing on the validation . Now to relax and try to regrow some of my hair .
Thank you so much again for help and direction on this.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
EvilLinux is offline Offline
77 posts
since Sep 2009
Sep 28th, 2009
0

Re: direct robot

You could also use the Abs method to ease your testing of the fictive coordinates. Like in : if (Math.Abs(X)>100)...
Good luck and happy programming!
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: auto scaling in web application
Next Thread in C# Forum Timeline: Controls added to panel are moving down when repainted





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC