如何在控制台应用程序中创建一个点? [英] How to create a point in console app?

查看:94
本文介绍了如何在控制台应用程序中创建一个点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制台应用程序中创建一个点
我尝试了以下代码,它正在运行,但我看不到要点.

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.

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();
        }
    }
}

推荐答案

好吧,不,你不会的.

原因如下:
1)这是一个控制台应用程序.这意味着它没有图形用户界面,它具有基于文本的界面.控制台应用程序不显示线条,圆圈,按钮或文本以外的任何内容.请尝试使用WinForms应用程序.

2)这是重点. IE.它是在空间中的位置.如有需要,请提供地图参考.它没有任何要显示的内容.如果我给您的房子发送一封信(解决行星表面上的一个点),但不会自动将您的房子涂成红色!

一个点没有大小,因此看不到-您需要(例如)在两个点之间画一条线!

创建一个Winforms应用程序,然后在窗体设计窗口中,查看属性"窗格.选择事件"按钮-看起来像闪电-并滚动到绘画"事件.双击它,然后将其显示为代码时,将此代码添加到处理程序例程中:
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:
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.


您刚刚定义了一个新点,不能放在任何地方.

为了实际绘制某些东西,我认为您正在尝试使用Windows Forms应用程序,在该应用程序中您将在其中绘制表单,例如线条(请参见示例: ^ ])
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[^])


这篇关于如何在控制台应用程序中创建一个点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆