sábado, 15 de junio de 2013

IPOINT

En esta aplicación utiliza 4 textBox en donde cada uno tiene las cordenadas del puntero del raton al hacer click en alguna parte de la forma, esto se hace mediante un evento de la forma llamada MouseDown y las coOrdenadas  X y Y.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace linea_4_5_14_feb
{
    public partial class Form1 : Form
    {

        Point p1;
        Point p2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            p1 = new Point(int.Parse(textBox1.Text), int.Parse(textBox2.Text));
            p2 = new Point(int.Parse(textBox3.Text), int.Parse(textBox4.Text));

            Graphics g = CreateGraphics();

            g.DrawLine(Pens.Azure, p1.X, p1.Y, p2.X, p2.Y);
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            p1 = new Point(e.X, e.Y);
            //p1.X = e.X;
            textBox1.Text = p1.X.ToString();
           // p1.Y = e.Y;
            textBox2.Text = p1.Y.ToString();
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            p2 = new Point(e.X, e.Y);
            //p1.X = e.X;
            textBox3.Text = p2.X.ToString();
            // p1.Y = e.Y;
            textBox4.Text = p2.Y.ToString();
        }
    }
}




No hay comentarios:

Publicar un comentario