Tema: Grafico C#
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/10/2013, 15:08
Avatar de cronopiomx
cronopiomx
 
Fecha de Ingreso: mayo-2012
Ubicación: Programing Cloud
Mensajes: 282
Antigüedad: 12 años
Puntos: 28
Respuesta: Grafico C#

Hola, aqui tienes 1 ejemplo que lee 1 fichero con coordenadas y despues dibuja lineas de punto a punto.

Ejemplo del Fichero.txt
20, 80
30, 40
35, 60
45, 80
45, 90

Código:
using System.Drawing;
using System.IO;

namespace PaintLines
{    
    public partial class Form1 : Form
    {
        private Point[] points;

        public Form1()
        {
            InitializeComponent();
            CargarPuntosFichero();
        }

        private void CargarPuntosFichero()
        {
            points = new Point[5];

            const string fic = @"FICHERO.txt";
            string texto;

            System.IO.StreamReader sr = new System.IO.StreamReader(fic); //lectura del fichero
            int i =0;

            while((texto = sr.ReadLine())!=null) {
                
                string[] pair = texto.Trim().Split(',');
                points[i].X = Convert.ToInt32(pair[0]);
                points[i].Y = Convert.ToInt32(pair[1]);

                i++;                
            }
            sr.Close();
        }       

        private void panel1_Paint(object sender, PaintEventArgs e)
        {            
            Pen pen = new Pen(Color.Blue, 3);

            for (int i = 0; i < points.Length-1; i++)            
                e.Graphics.DrawLine(pen, points[i], points[i+1]);            
        }        
    }
}
saludos