using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace CCD{ public partial class Form3 : Form { UserControl1 UserControl1 = new UserControl1(); private int ST_X, ST_Y, ED_X, ED_Y , index = 1; private bool Clicked = false; public bool LINE = false; private string CtrlName; public Form3() { InitializeComponent(); } private void DrawLine(int sx, int sy, int ex, int ey) { Graphics G = this.CreateGraphics(); Pen P = new Pen(Color.Red, 1); Point p1 = new Point(sx, sy); Point p2 = new Point(ex, ey); G.DrawLine(P, p1, p2); P.Dispose(); } private void Form3_Load(object sender, EventArgs e) { Helper.ControlMover.Init(UserControl1); } private void button1_Click(object sender, EventArgs e) { index += 1; UserControl1 = new UserControl1(); this.Controls.Add(UserControl1); Helper.ControlMover.Init(UserControl1); CtrlName = "UsrCtrl" + index; UserControl1.Name = CtrlName; textBox1.Text = UserControl1.Name.ToString(); } private void button2_Click(object sender, EventArgs e) { LINE = true; } public void LINEPOINTS(object sender, EventArgs e) { UserControl user = new UserControl(); if (!Clicked) { Clicked = true; ST_X = user.Location.X; ST_Y = user.Location.Y; } else { ED_X = user.Location.X; ED_Y = user.Location.Y; textBox1.Text = ED_Y.ToString(); Clicked = false; } } }}
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Text;using System.Windows.Forms;namespace CCD{ public partial class UserControl1 : UserControl { public int ST_X, ST_Y, ED_X, ED_Y; public Point loc; private bool Clicked = false; public UserControl1() { InitializeComponent(); // this.Click += new System.EventHandler(this.myEven); } private void myEven(object sender, System.EventArgs e) { /* if (!Clicked) { Clicked = true; ST_X = this.Location.X; ST_Y = this.Location.Y; } else { ED_X = this.Location.X; ED_Y = this.Location.Y; Clicked = false; }*/ loc.X = this.Location.X; loc.Y = this.Location.Y; } private void DrawLine(int sx, int sy, int ex, int ey) { Graphics G = this.CreateGraphics(); Pen P = new Pen(Color.Red, 1); Point p1 = new Point(sx, sy); Point p2 = new Point(ex, ey); G.DrawLine(P, p1, p2); P.Dispose(); } private void hotspot1_MouseHover(object sender, EventArgs e) { hotspot1.BorderStyle = BorderStyle.FixedSingle; } private void hotspot1_MouseLeave(object sender, EventArgs e) { hotspot1.BorderStyle = BorderStyle.None; } private void hotspot1_Click(object sender, EventArgs e) { } private void UserControl1_Click(object sender, EventArgs e) { // this.myEven(sender, e); Form3 F = new Form3(); F.LINEPOINTS(sender,e); } }}