Click here to Skip to main content
14,830,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text file with XY coordinates.
For example these are the points in my file

-23.68 0.09
-23.67 0.76
-23.66 1.43
-23.68 2.1
-23.6 2.78
-23.58 3.45

My first line should be drawn from Point 1(-23.68 , 0.09) to Point 2 (-23.67 , 0.76) and the second line from Point 2(-23.67 , 0.76) to Point 3 (-23.66 , 1.43).

I want to draw these lines on a form.

What I have tried:

Im begiiner with C# hence I'm not aware of C# GUI
Posted
Updated 4-Mar-21 23:40pm

Create a Panel on your form, and handle it's Paint event.

In the event handler, the second parameter includes a Graphics property, which allows you to draw on the panel surface.
Then it's just a case of calling DrawLine
C#
Graphics g = e.Graphics;
g.DrawLine(Pens.Black, new PointF(-23.68F, 0.09F), new PointF(-23.67F, 0.76F));
g.DrawLine(Pens.Black, new PointF(-23.67F, 0.76F), new PointF(-23.66F, 1.43F));
You may have to play with scaling and / or center points in order to see your data though, as Windows coordinates start with (0, 0) at teh top left corner, and increase down and right.
   
First, your x,y Point values are all negative: why would you want lines that would not appear, if drawn, in any Control's Paint Event ?

Second, if you wish to have hit-detection on the lines you draw, there is another technique you can use: I'll post an example if you request it.
   
What is the sense of your question ?
In my opinion your collection of points could be a Chart. If Yes : there is a free Tool (MSChart) availible in the Internet :
Download Microsoft Chart Controls for Microsoft .NET Framework 3.5 from Official Microsoft Download Center[^]
Here you only need to add the Points to the Chart ... (and you get your line)
   

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