Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In VB6 when I wanted to Capture a part of a form, I would do the following:

 

Release Capture

lRtn = SendMessage(Me.hwnd, _ WM_NCLBUTTONDOWN,HTCAPTION,0&)

 

This would set the control under the mouse to be Captured like the Caption bar normally is. Thus I could drag a form around by any control I wanted.

 

Does any one know how to do this in VB.NET? I'd rather not call the Win32 API if I can avoid it.

 

Thanks,

 

ralan

  • Leaders
Posted

i know you say you don't want to use the api way , but i knocked this up for you anyway ( as it's still ok / sometimes necassary to use Api calls in .net / C# )

'/// in your Form...
   Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
       If e.Button = MouseButtons.Left Then
           _Win32.ReleaseCapture()
           _Win32.SendMessage(Me.Handle.ToInt32, _Win32.WM_NCLBUTTONDOWN, _Win32.HTCAPTION, 0)
       End If
   End Sub

'/// seperate Class ...

Public Class _Win32
   Public Declare Function ReleaseCapture Lib "user32.dll" () As Integer
   Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Integer) As Integer

   Public Const WM_NCLBUTTONDOWN As Integer = &HA1
   Public Const HTCAPTION As Integer = 2

End Class

Posted

Nice!

 

Thanks for the replies. I'm glad to learn more than one way to solve a problem. Adds for flexibility down the road. Again, thanks!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...