Runtime dragging a control
-
Simple question--one would think (...but I'm pulling my hair out). I'm trying to drag a control (say a button) in a Windows app at runtime. The button, as I drag it, appears to split into two button images (with each "instance" having its location updated about half the time.) My code, in the Form1 class: ----------------------------------------------------- bool isDragging = false; Point anchor; private void button1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isDragging = true; anchor = new Point(e.X,e.Y); } } private void button1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && isDragging) { button1.Location += new Size(e.X-anchor.X, e.Y-anchor.Y); anchor = new Point(e.X,e.Y); } } ----------------------------------------------------- Please save my hair!! THANKS, Tom
-
Simple question--one would think (...but I'm pulling my hair out). I'm trying to drag a control (say a button) in a Windows app at runtime. The button, as I drag it, appears to split into two button images (with each "instance" having its location updated about half the time.) My code, in the Form1 class: ----------------------------------------------------- bool isDragging = false; Point anchor; private void button1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isDragging = true; anchor = new Point(e.X,e.Y); } } private void button1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && isDragging) { button1.Location += new Size(e.X-anchor.X, e.Y-anchor.Y); anchor = new Point(e.X,e.Y); } } ----------------------------------------------------- Please save my hair!! THANKS, Tom