using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace Kresleni { public partial class MyPort : UserControl { public MyControl panel; public double relx, rely; public bool resize; public MyPort () { InitializeComponent(); } private int X0, Y0; private bool stisknuto; private void MyPort_MouseDown(object sender, MouseEventArgs e) { stisknuto = true; X0 = e.X; Y0 = e.Y; } private void MyPort_MouseMove(object sender, MouseEventArgs e) { if (stisknuto) { if (e.Button == MouseButtons.Left) { this.Left += e.X - X0; this.Top += e.Y - Y0; if (panel != null) correct (); } } } private void MyPort_MouseUp(object sender, MouseEventArgs e) { stisknuto = false; } public void place() { Left = panel.Left + (int)Math.Round (relx * (panel.Width-Width)); Top = panel.Top + (int)Math.Round (rely * (panel.Height-Height)); Parent = panel.Parent; BringToFront(); } public void correct() { panel.Left = Left - (int) Math.Round (relx * (panel.Width-Width)); panel.Top = Top - (int)Math.Round (rely * (panel.Height - Height)); foreach (Control c in Parent.Controls) { MyPort p = c as MyPort; if (p != null && p.panel == this.panel && p != this) p.place(); } } } }