By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,920 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,920 IT Pros & Developers. It's quick & easy.

Moving a form with mouse-down on a picture control

VBWheaties
100+
P: 145
In vb.net, I want to allow a user to click and drag a form like what is supported when you click and drag a moveable forms title bar: you click and hold titlebar, then move the mouse, the form moves with the mouse. Ide like to be able to do this but with an area on the form.

For example, I have a picturebox on the form. When the mouse is down on the picture and they move the mouse, I would like the form to move with it.

Any idea how this can be done?
Mar 3 '08 #1
Share this Question
Share on Google+
3 Replies


P: 1
Hi,

The whole form can be moved by clicking on any location other than the title bar using the code in the below given link.This example considers that there is no border for the form.That case can be ignored.

TechiSolutions Solution

Cheers..
Mar 4 '08 #2

VBWheaties
100+
P: 145
Hi,

The whole form can be moved by clicking on any location other than the title bar using the code in the below given link.This example considers that there is no border for the form.That case can be ignored.

TechiSolutions Solution

Cheers..
Thanks for the link.
I could not get it to work. More specifically, the set to the property of the m.result does not do anything.
I'll keep playing with it until it works.
I'm sure i'll be able to do something with it.
Thanks again

btw, here is the code (*converted from C# to VB):
Expand|Select|Wrap|Line Numbers
  1.     Protected Overrides Sub WndProc(ByRef m As Message)
  2.         ' Let the base class have first crack
  3.         MyBase.WndProc(m)
  4.         Dim WM_NCHITTEST As Integer = 132 ' winuser.h
  5.         ' If the user clicked on the client area,
  6.         ' ask the OS to treat it as a click on the caption
  7.         If m.Msg <> WM_NCHITTEST Then
  8.             Return
  9.         End If
  10.         Dim HTCLIENT As Integer = 1
  11.         Dim HTCAPTION As Integer = 2
  12.         If m.Result.ToInt32() = HTCLIENT Then
  13.             m.Result = CType(HTCAPTION, IntPtr)
  14.         End If
  15.     End Sub
  16.  
Mar 4 '08 #3

Expert 5K+
P: 8,434
Did you manage to get this working?
Mar 25 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.