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. Drag and drop

Drag and drop

Scheduled Pinned Locked Moved C#
helpquestion
3 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.
  • V Offline
    V Offline
    valiovalio
    wrote on last edited by
    #1

    Hello, I`m trying to create label and then I`m trying to move it on the form, but when I drag label I see two labels instead of one. what should I do to fix it? bool a; Label l; private void button1_Click(object sender, EventArgs e) { l = new Label(); l.Text = "text"; Controls.Add(l); l.MouseDown += new System.Windows.Forms.MouseEventHandler(mouse_down); l.MouseUp += new System.Windows.Forms.MouseEventHandler(mouse_up); l.MouseMove += new System.Windows.Forms.MouseEventHandler(mouse_move); Form1.ActiveForm.AllowDrop = true; } private void mouse_down(object sender, MouseEventArgs e) { a = true; } private void mouse_up(object sender, MouseEventArgs e) { a = false; } private void mouse_move(object sender, MouseEventArgs e) { if (a) { l.Location = e.Location; } } arnas

    R 1 Reply Last reply
    0
    • V valiovalio

      Hello, I`m trying to create label and then I`m trying to move it on the form, but when I drag label I see two labels instead of one. what should I do to fix it? bool a; Label l; private void button1_Click(object sender, EventArgs e) { l = new Label(); l.Text = "text"; Controls.Add(l); l.MouseDown += new System.Windows.Forms.MouseEventHandler(mouse_down); l.MouseUp += new System.Windows.Forms.MouseEventHandler(mouse_up); l.MouseMove += new System.Windows.Forms.MouseEventHandler(mouse_move); Form1.ActiveForm.AllowDrop = true; } private void mouse_down(object sender, MouseEventArgs e) { a = true; } private void mouse_up(object sender, MouseEventArgs e) { a = false; } private void mouse_move(object sender, MouseEventArgs e) { if (a) { l.Location = e.Location; } } arnas

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      You only see one Label but I think it is probably flickering very fast between two locations. Set the location this way: l.Location = this.PointToClient(l.PointToScreen(new Point(e.X, e.Y))); The location you get in the event arguments is relativ to the labels top left position so you have to calcualte the position you want to ste on the form.

      V 1 Reply Last reply
      0
      • R Robert Rohde

        You only see one Label but I think it is probably flickering very fast between two locations. Set the location this way: l.Location = this.PointToClient(l.PointToScreen(new Point(e.X, e.Y))); The location you get in the event arguments is relativ to the labels top left position so you have to calcualte the position you want to ste on the form.

        V Offline
        V Offline
        valiovalio
        wrote on last edited by
        #3

        Thanks;) now it work:)

        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