I\'m pretty new to C# and I\'m trying to do something but without much success. I am trying to use the class Point
(the one with coordinates).
This is t
Move your cursor to the Point
in your code and use the swift keyboard shortcut: Alt+Shift+F10. In there, you can easily attach the necessary namespace - in your case, it will be System.Drawing
.
With that shortcut you can decide if you want to attach the whole namespace, or just use it localy, like SystemDrawing.Point _Point = new SystemDrawing.Point();
Bear in mind that you may have to add the library reference - you use a console program, which doesn't have Windows Forms .dll files (as it would be unwise to attach all the unnecessary libraries). You have to add one manually.
Go to you project in solution explorer, right click on References
, add reference
, Assemblies
and then check the System.Drawing
. Ounce you add that and the correct namespace (using System.Drawing
), it will work.
The Point
class is located at System.Drawing
, so at the top you should write
using System.Drawing
If you just want to use a simple structure for 2 ints, you can use the Tuple class (from the System namespace).
Tuple<int, int> point = new Tuple<int, int>(2, 5);
In time: As stated by @Aaron Hudon on comments, be aware that a Tuple is a class (so, by using it you'll be having an instance's reference) while a Point is a struct. Thanks for the observation Aaron Hudon.
The Point
structure is a part of the System.Drawing
namespace.
You can either reference this namespace or create your own Point structure, which, if you only need it as a coordinate container could be a very simple structure.
Something like:
public struct Point
{
public int X {get;set;}
public int Y {get;set;}
}
Altho, the original Point
struct in the System.Drawing
namespace got a few more functions than the above code (which obviously don't have any, hehe). If you need those, I would recommend including the System.Drawing
namespace instead of making your own, cause it would probably take more time than you wish that it took for such a simple structure.
http://msdn.microsoft.com/library/system.drawing.point.aspx
you need add using System.Drawing
at top.
You should add a reference to your solution, to the namespace System.Drawing
.
From the tab 'Solution Explorer', right click on 'References' and select 'Add Reference', as shown below:
In the new window, type in the search bar 'System.Drawing
'. Double click in the results found and click the button 'OK'.
Now, in your code, where the other using
statements are declared, add the following line:
using System.Drawing;
Note: I noticed you're creating a new Console application. Be aware that, if you want to create a basic user interface, the System.Drawing.Point
structure won't help you, because in a Console application you cannot interact with the user using buttons, labels and coordinates useful to place your UI items. In a Console application, you can interact only using plain text.
If you want to create a simple application with a basic user interface, create instead a Windows Forms application.