How to make Form unmovable ?

capedech

Well-known member
Joined
Oct 29, 2008
Messages
62
Programming Experience
Beginner
I'm curious, Can we set a form so that it can't be moved ?
If I'm not wrong, I think we can do it in VB.
Can we do it in VB.NET too ?
 
Here is one Win32 way: 32.18 How do I prevent a user from moving a form at run time?
and here is another:
VB.NET:
Private Const WM_MOVING As Int32 = &H216
Private Const [TRUE] As Int32 = 1

Private Structure RECT
    Public Left As Int32
    Public Top As Int32
    Public Right As Int32
    Public Bottom As Int32

    Public Sub New(ByVal r As Rectangle)
        Me.Left = r.Left
        Me.Top = r.Top
        Me.Right = r.Right
        Me.Bottom = r.Bottom
    End Sub
End Structure

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    If m.Msg = WM_MOVING Then            
        Runtime.InteropServices.Marshal.StructureToPtr(New RECT(Me.Bounds), m.LParam, False)
        m.Result = New IntPtr([TRUE])        
    End If
    MyBase.WndProc(m)
End Sub
 
Back
Top