Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Runtime dragging a control

Runtime dragging a control

Scheduled Pinned Locked Moved C#
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hain
    wrote on last edited by
    #1

    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

    I 1 Reply Last reply
    0
    • H hain

      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

      I Offline
      I Offline
      IdUnknown
      wrote on last edited by
      #2

      Before all your hairs are gone. Read this article. http://www.codeproject.com/cs/miscctrl/CSPickBoxSample1.asp#xx672690xx[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups