Click here to Skip to main content
16,022,417 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
how to track and drop(move) lable in runtime in .net windows application using c#
Posted

1 solution

Hi

You have to write below 3 mouse events to move the label control at runtime

private Boolean dragInProgress = false;
int MouseDownX = 0;
int MouseDownY = 0;

private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.dragInProgress = false;
            }
            return;
        }

private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            if (!this.dragInProgress)
            {
                this.dragInProgress = true;
                this.MouseDownX = e.X;
                this.MouseDownY = e.Y;
            }
            return;

        }


private void label1_MouseMove(object sender, MouseEventArgs e)
       {
           if (dragInProgress)
           {
               Point temp = new Point();
               temp.X = this.label1.Location.X + (e.X - MouseDownX);
               temp.Y = this.label1.Location.Y + (e.Y - MouseDownY);
               this.label1.Location = temp;
           }
           return;
       }
 
Share this answer
 
Comments
Mathuraiveeran.P 27-Sep-10 2:29am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900