Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a point in console application
i Tried following code and it is running but i am not able to see the point.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Media;
using System.Configuration;



namespace p_6
{
    class Program
    {
        static void Main(string[] args)
        {
            // C# - Requires reference to System.Drawing
            // Create point
            System.Drawing.Point p = new System.Drawing.Point(20, 90);
            Console.ReadLine();
        }
    }
}
Posted

Well, no, you won't.

There are a few reasons for that:
1) It's a console app. That means that it doesn't have a Graphical User Interface, it has a text based interface. Console Apps don't show lines, or circles, or buttons, or anything other than text. Try a WinForms application instead.

2) It's a point. I.e. it is a position in a space. A map reference if you like. It doesn't have anything to display. If I send a letter to you house (addressing a point on the planet surface) that does not automatically paint your house red!

A point does not have a size, so it can't be seen - you need to (for example) draw a line between two points!

Create a Winforms apps, and in your form design window, look at the Properties pane. Select the "Events" button - it looks like a lightning bolt - and scroll through to the Paint event. double click it and add this code to the handler routine when it appears as code:
C#
Pen red = new Pen(Color.Red, 3);
Point p1 = new Point(100, 100);
Point p2 = new Point(200, 200);
e.Graphics.DrawLine(red, p1, p2);
red.Dispose();
Now when you run your application, it will draw a red line, three pixels wide, diagonally on your form.
 
Share this answer
 
Comments
shivani 2013 11-Sep-11 5:13am    
Thank You for explaining.....I have a question in Turbo c we give the header file #include(graphics.h) and it is also console then why we cant use such namspaces for it though its not there in c# console
OriginalGriff 11-Sep-11 5:23am    
Well, the most obvious answer is: It's not C, it's C#, and C# does not need or use include files!
You can use libraries such as the Turbo C ones you are used to, but it isn't really a good idea - it's like buying a Ferrari and only using first gear because you are used to driving a mini.
C# and the .NET framework adds a heck of a lot that would have to be done by hand in Turbo C - for example, in C# to create a List of Customers is simple:
List<customer> customers = new List<customers>;
That gives you a full list, with add, remove, iterate, search, all strongly typed so that only Customers can be added. How much work is that in Turbo C? :laugh:

Forget what you did use, and look instead at what you can use now - you will find that you (generally) don't need the low-level stuff, because higher level, easier to use constructs are provided instead. And when you do need to use low level, it's there - you just have to learn how!

I would strongly suggest that you get a book and follow it, complete with the examples - if you just try to do things you used to in Turbo C you will miss out on so much useful stuff because you won't even know it is there!
Yo have just defined a new point, you're not placing it anywhere.

In order to actually draw something I think you're trying to use a Windows Forms application where you would have a form where to draw, for example a line (see the example: http://msdn.microsoft.com/en-us/library/system.drawing.point.aspx[^])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900