Click here to Skip to main content
15,892,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm Trying with this example but it's not working
C#
public frmChequeFormat()
    {
        InitializeComponent();
        gbCheque.MouseMove += gbCheque_MouseMove;
    }
    bool mDown = false;
    private void gbCheque_MouseMove(object sender, MouseEventArgs e)
    {
        if (mDown)
        {
            label13.Location = e.Location;
        }
    }
    private void label13_MouseDown(object sender, MouseEventArgs e)
    {
        mDown = true;
    }
    private void label13_MouseUp(object sender, MouseEventArgs e)
    {
        mDown = false;
    }
Posted
Updated 28-Jul-15 23:37pm
Comments
lukeer 29-Jul-15 5:48am    
label13_MouseDown() doesn't subscribe to the MouseDown event. Therefore, it won't get called.
Zohaib Hassan DxB 29-Jul-15 7:12am    
Can you me your send code what ever you are saying. Because I try to best but still problem is there
lukeer 29-Jul-15 7:30am    
I have no code. It's your project. You have the code.
See my answer.
Zohaib Hassan DxB 29-Jul-15 7:41am    
yes i share my code you can check in Question. but problem is that when label move there appear two label instead of one

Not sure why you handle the group box mouse move. Would it be resonable to handle the labels mouse move, for example
C#
private void label13_MouseDown(object sender, MouseEventArgs e) {
   mDown = true;
}

private void label13_MouseUp(object sender, MouseEventArgs e) {
   mDown = false;
}

private void label13_MouseMove(object sender, MouseEventArgs e) {
   if (mDown) {
      label1.Location = new Point(label1.Location.X + e.Location.X, label1.Location.Y + e.Location.Y);
   }
}
 
Share this answer
 
v2
Comments
Zohaib Hassan DxB 29-Jul-15 6:46am    
I try this code but when i move label, that time 2 label appear and move, not single label. Kindly try it on your system. Thanx
Wendelius 29-Jul-15 12:32pm    
The flickering and seeing 2 labels happens because the position changes wrong if the new position is set directly from eventargs. The problem is that the position in eventargs is relative to the starting point. See the modified mousemove event handler in the answer.
You need MouseDown, MouseUp and MouseMove. All of them within the GroupBox. So you need to add this to your form constructor:
C#
public frmChequeFormat()
{
    label13.MouseDown += label13_MouseDown;
    label13.MouseUp += label13_MouseUp;
    label13.MouseMove += label13_MouseMove;  // You already have this one.
}
Then rename your gbCheque_* methods accordingly so they get called.

[Edit]
Renamed event and method names above from gbCheque* to label13*

The label shields your groupbox from getting those events. They are routed to the label instead. Hence the renaming in contrast to my first attempt.

Events should still be routed to the label, but now call handlers from there. At least until user moves the mouse very quickly to the upper left so it leaves the label and therefore causes label events to stop firing.
[/Edit]
 
Share this answer
 
v2
Comments
Zohaib Hassan DxB 29-Jul-15 8:16am    
not working :( before this label move but not with mouse, after this code label stuck and don't move
lukeer 29-Jul-15 8:43am    
I updated my answer. What do you mean by "move but not with mouse"?
Man, if only someone wrote an article on doing just this.

Create your Own Runtime Movable Windows Forms Controls[^]
 
Share this 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