Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] Drag a button inside the form.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Morph.C
Cheater
Reputation: 0

Joined: 15 Aug 2009
Posts: 29

PostPosted: Sat Sep 12, 2009 6:51 pm    Post subject: [C#] Drag a button inside the form. Reply with quote

Well, in the title as specified in a nutshell, here I hope your understand me.

I have a button, which has an image, then, to give click to button (without drop the click), I want to move the mouse, move the button. until where release the mouse again.

I hope understand me, thanks in advance. and sorry for my english, but I speak Spanish.
Embarassed
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Sep 12, 2009 8:51 pm    Post subject: Reply with quote

Code:
        bool pDragging = false;
        Point pMousePosition = Point.Empty;

        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            pMousePosition = button1.PointToClient(Control.MousePosition);
            pDragging = true;
        }

        private void button1_MouseUp(object sender, MouseEventArgs e)
        {
            pDragging = false;
        }

        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            if (pDragging && e.Button == MouseButtons.Left)
            {
                Point theFormPosition = this.PointToClient(Control.MousePosition);
                theFormPosition.X -= pMousePosition.X;
                theFormPosition.Y -= pMousePosition.Y;
                button1.Location = theFormPosition;
            }
        }


I'd encapsulate this in a custom button class, to make it more reusable.
Back to top
View user's profile Send private message
Morph.C
Cheater
Reputation: 0

Joined: 15 Aug 2009
Posts: 29

PostPosted: Sun Sep 13, 2009 2:32 am    Post subject: Reply with quote

Works!! thanks!!! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites