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 


[VB.NET] Drag form on label

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

Joined: 05 Jan 2008
Posts: 652

PostPosted: Sat Jan 24, 2009 2:47 am    Post subject: [VB.NET] Drag form on label Reply with quote

does anyone has a code so i can drag a form by clicking on a label?
i already searchd on google but without succes

_________________
why Hitler? why did you had to pm me that child porn?
btw Hitler, Shave your pubic hair

PM Me for Hitler's Nude pics
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Jan 24, 2009 3:12 am    Post subject: Reply with quote

The easiest way I think is to just use SendMessage, from the Win32 API.

On the MouseDown event for whatever control you want, send iWM_NCLBUTTONDOWN, with a wParam of HT_CAPTION.

Or maybe even better, you can override WndProc, and handle WM_NCHITTEST yourself.
Back to top
View user's profile Send private message
Xeleron
Grandmaster Cheater
Reputation: 0

Joined: 05 Jan 2008
Posts: 652

PostPosted: Sat Jan 24, 2009 3:24 am    Post subject: Reply with quote

ok.... can you maybe give me a total code of it xD , i a bit inexpierenced with code's and stuff xD
i am more a guy of design and stuff xD

_________________
why Hitler? why did you had to pm me that child porn?
btw Hitler, Shave your pubic hair

PM Me for Hitler's Nude pics
Back to top
View user's profile Send private message MSN Messenger
FullyAwesome
I post too much
Reputation: 0

Joined: 05 Apr 2007
Posts: 4438
Location: Land Down Under

PostPosted: Sat Jan 24, 2009 3:54 am    Post subject: Reply with quote

matthew2010 wrote:
ok.... can you maybe give me a total code of it xD , i a bit inexpierenced with code's and stuff xD
i am more a guy of design and stuff xD


EDIT: after all that i found a link for you that shows a vb.net example. here. as explained below, instead of in the mousedown event of the form, put it in the event of the label.


i'm sorry it's in C#, but you should get the gist of things and know how to easily do this in vb.net. as slovach said, using the SendMessage API with WM_NCLBUTTONDOWN and HT_CAPTION is quite easy.

constant variables
Code:
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;


APIs
Code:
[DllImport("USER32.DLL")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
        public static extern bool ReleaseCapture();


(the event for mousedown on the actual form)
Code:
private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }


quite simple, you're just basically using SendMessage. for a label, double click it to go to the mousedown event of the label and put the SendMessage code there.

_________________
Back to top
View user's profile Send private message MSN Messenger
Xeleron
Grandmaster Cheater
Reputation: 0

Joined: 05 Jan 2008
Posts: 652

PostPosted: Sat Jan 24, 2009 4:37 am    Post subject: Reply with quote

that code from the explane doesn't work ..
_________________
why Hitler? why did you had to pm me that child porn?
btw Hitler, Shave your pubic hair

PM Me for Hitler's Nude pics
Back to top
View user's profile Send private message MSN Messenger
FullyAwesome
I post too much
Reputation: 0

Joined: 05 Apr 2007
Posts: 4438
Location: Land Down Under

PostPosted: Sat Jan 24, 2009 6:20 pm    Post subject: Reply with quote

matthew2010 wrote:
that code from the explane doesn't work ..


what's the errors you get from following this?

_________________
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Jan 24, 2009 7:46 pm    Post subject: Reply with quote

just handle WM_NCHITTEST

Code:
protected override void WndProc(ref Message m)
{
   const int WM_NCHITTEST   = 0x84;
   const int HTCAPTION      = 0x02;

   switch(m.Msg){
      case WM_NCHITTEST:
         m.Result = (IntPtr)HTCAPTION;
         break;

      default:
         base.WndProc(ref m);
   }
}
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Sat Jan 24, 2009 10:53 pm    Post subject: Reply with quote

You don't need to call the win32 API's in order to move the form. All you have to do is remember the location of the label when you hold down the mouse and then move it based on that.
Code:

Point labelLocation;
bool isEnable = false;

private void label1_MouseDown(object sender, MouseEventArgs e)
        {
           if (e.Button == MouseButtons.Left)
            {
                isEnable = true;
                labelLocation = new Point(e.X, e.Y);
            }
        }

        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isEnable)
            {
                this.Location = new Point(this.Location.X + (e.X - labelLocation.X),
                    this.Location.Y + (e.Y - labelLocation.Y));
            }
        }

        private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            isEnable = false;
        }


Last edited by killersamurai on Thu Jan 29, 2009 2:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Jan 29, 2009 1:35 pm    Post subject: Reply with quote

killersamurai wrote:
You don't need to call the win32 API's in order to move the form. All you have to do is remember the location of the label when you hold down the mouse and then move it based on that.
Code:

Point labelLocation;
bool isEnable = false;

private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            isEnable = true;
            labelLocation = new Point(e.X, e.Y);
        }

        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isEnable)
            {
                this.Location = new Point(this.Location.X + (e.X - labelLocation.X),
                    this.Location.Y + (e.Y - labelLocation.Y));
            }
        }

        private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            isEnable = false;
        }

that's c# not vb.. but the code is neat Wink

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Thu Jan 29, 2009 2:33 pm    Post subject: Reply with quote

Even though it's c#, it will still be the same in vb.net. The difference is the syntax.

Code:

Public Class Form1
    Private labelLocation As Point
    Private isEnable As Boolean

    Private Sub Label1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            isEnable = True
            labelLocation = New Point(e.X, e.Y)
        End If
    End Sub

    Private Sub Label1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
        If isEnable Then
            Me.Location = New Point(Me.Location.X + (e.X - labelLocation.X), Me.Location.Y + (e.Y - labelLocation.Y))
        End If
    End Sub

    Private Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
        isEnable = False
    End Sub
End Class
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