| | |
direct robot
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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.
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.
Last edited by ddanbe; Sep 27th, 2009 at 5:12 pm.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
•
•
•
•
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.
C# Syntax (Toggle Plain Text)
get { if (location.X > 100 && location.Y > -100) { throw new ArgumentException("You can't do that!"); }
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?
Why not make your own robotexception class?
Use it:
c# Syntax (Toggle Plain Text)
class RobotException : Exception { public string robotstr; public RobotException(string message) : base(message) { robotstr = message; } }
c# Syntax (Toggle Plain Text)
try { //something went wrong so throw exception throw new RobotException("no no"); } catch (RobotException ex) { MessageBox.Show(ex.robotstr); }
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
form:
robot.cs:
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
C# Syntax (Toggle Plain Text)
private void go10Btn_Click(object sender, EventArgs e) { try { throw new robotexception("You can't go that far; limited to 100units of movement"); } catch (robotexception ex) { MessageBox.Show(ex.robotstr); } //Go 10. myRobot.Move(10); myRobot.Draw(robotpanel); //Update location info. robotlocationLlb.Text = myRobot.location.ToString(); }
C# Syntax (Toggle Plain Text)
class robotexception : Exception { public string robotstring; public robotexception(string message) : base(message) { robotstring = message; } }
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.
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
•
•
•
•
form:
robot.cs:C# Syntax (Toggle Plain Text)
private void go10Btn_Click(object sender, EventArgs e) { try { throw new robotexception("You can't go that far; limited to 100units of movement"); } catch (robotexception ex) { MessageBox.Show(ex.robotstr); } //Go 10. myRobot.Move(10); myRobot.Draw(robotpanel); //Update location info. robotlocationLlb.Text = myRobot.location.ToString(); }
C# Syntax (Toggle Plain Text)
class robotexception : Exception { public string robotstring; public robotexception(string message) : base(message) { robotstring = message; } }
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
•
•
Join Date: Sep 2009
Posts: 77
Reputation:
Solved Threads: 0
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.
"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.
![]() |
Similar Threads
- Game: Robots (Class, Constructors, etc.) (C++)
- Python for Laptop Robot Speech recognition and TTS. (Python)
- Siebel Systems Engineer needed (Tech / IT Consultant Job Offers)
- News Story: Linux Powered Robot Dog (Linux Servers and Apache)
- Slow CPU causes damage to robot (C)
- direct X version problems (Windows 95 / 98 / Me)
- Direct CD: PC to Mac (Mac Software)
Other Threads in the C# Forum
- Previous Thread: auto scaling in web application
- Next Thread: Controls added to panel are moving down when repainted
| Thread Tools | Search this Thread |
.net 6 2008 access activedirectory ado.net advice app array asp.net avltree basic c# camera check checkbox code combobox console contorl control copy database datagrid datagridview datetime dba developer development directrobot disabled drawing droid dubai e-commerce editor element email file files foreach forloop form forms gdi+ httpwebrequest index insert javascript linux list login mailmerge math mono mysql news open oracle paypal photoshop php post print programming read remote remoting resourcefile richtextbox robot smoobjects sql sql-server string text textbox totaldays treeview upload uploadatextfile user usercontrol validation validator vb video visual visualbasic visualstudio webbrowser webdevelopemnt webdevelopment whileloop windows winforms wordautomation working wpf xml







