I can't find a property to lock the form so that you can't drag it around by
the title bar. The locked property doensn't do this.

Re: Property to lock form at run time by Morten

Morten
Fri Sep 03 10:11:22 CDT 2004

Hi TS,

The locked property is for locking the size of the form in the designer not at runtime.
Title bars are designed to be dragable so to prevent dragging remove the title bar (set borderstyle to none).

--
Happy coding!
Morten Wennevik [C# MVP]

Re: Property to lock form at run time by hirf-spam-me-here

hirf-spam-me-here
Fri Sep 03 10:55:01 CDT 2004

* "TS" <manofsteele@311.com> scripsit:
> I can't find a property to lock the form so that you can't drag it around by
> the title bar. The locked property doensn't do this.

From my FAQ (<URL:http://dotnet.mvps.org/dotnet/faqs/>):

Based on an implementation written by Tom Spink.

The code below defines a base class that provides a 'Moveable' property.
By inheriting from this class and setting the 'Moveable' property to
'False', the user will be prevented from moving then form:

\\\
Imports System.ComponentModel
Imports System.Windows.Forms

Public Class MoveableForm
Inherits Form

Private Const WM_NCLBUTTONDOWN As Int32 = &HA1
Private Const WM_SYSCOMMAND As Int32 = &H112

Private Const HTCAPTION As Int32 = &H2

Private Const SC_MOVE As Int32 = &HF010

Private m_Moveable As Boolean

Public Sub New()
MyBase.New()
Me.Moveable = True
End Sub

< _
Category("Behavior"), _
Description("Allows the form to be moved.") _
> _
Public Property Moveable() As Boolean
Get
Return m_Moveable
End Get
Set(ByVal Value As Boolean)
m_Moveable = Value
End Set
End Property

Protected Overrides Sub WndProc(ByRef m As Message)
If Not m_Moveable Then
If _
m.Msg = WM_SYSCOMMAND And _
m.WParam.ToInt32() = SC_MOVE _
OrElse _
m.Msg = WM_NCLBUTTONDOWN And _
m.WParam.ToInt32() = HTCAPTION _
Then
Return
End If
End If
MyBase.WndProc(m)
End Sub
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Re: Property to lock form at run time by TS

TS
Wed Sep 08 09:49:34 CDT 2004

Cool, let me give that a go and see if it works, becuase I need to keep the
title bar, so the previous post won't work

thank you

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:e0HBm5ckEHA.3392@TK2MSFTNGP15.phx.gbl...
> * "TS" <manofsteele@311.com> scripsit:
> > I can't find a property to lock the form so that you can't drag it
around by
> > the title bar. The locked property doensn't do this.
>
> From my FAQ (<URL:http://dotnet.mvps.org/dotnet/faqs/>):
>
> Based on an implementation written by Tom Spink.
>
> The code below defines a base class that provides a 'Moveable' property.
> By inheriting from this class and setting the 'Moveable' property to
> 'False', the user will be prevented from moving then form:
>
> \\\
> Imports System.ComponentModel
> Imports System.Windows.Forms
>
> Public Class MoveableForm
> Inherits Form
>
> Private Const WM_NCLBUTTONDOWN As Int32 = &HA1
> Private Const WM_SYSCOMMAND As Int32 = &H112
>
> Private Const HTCAPTION As Int32 = &H2
>
> Private Const SC_MOVE As Int32 = &HF010
>
> Private m_Moveable As Boolean
>
> Public Sub New()
> MyBase.New()
> Me.Moveable = True
> End Sub
>
> < _
> Category("Behavior"), _
> Description("Allows the form to be moved.") _
> > _
> Public Property Moveable() As Boolean
> Get
> Return m_Moveable
> End Get
> Set(ByVal Value As Boolean)
> m_Moveable = Value
> End Set
> End Property
>
> Protected Overrides Sub WndProc(ByRef m As Message)
> If Not m_Moveable Then
> If _
> m.Msg = WM_SYSCOMMAND And _
> m.WParam.ToInt32() = SC_MOVE _
> OrElse _
> m.Msg = WM_NCLBUTTONDOWN And _
> m.WParam.ToInt32() = HTCAPTION _
> Then
> Return
> End If
> End If
> MyBase.WndProc(m)
> End Sub
> End Class
> ///
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



Re: Property to lock form at run time by v-jetan

v-jetan
Wed Sep 08 20:31:20 CDT 2004

Hi TS,

Thanks for your feedback.

Sorry, I am not sure about the "previous post" you are talking about. I
think Herfried's reply should meet your need. This solution disable form's
mouse left button clicking on the title bar, also, it will intercept the
form's "Move" command of system menu. Through these 2 steps, we can prevent
a user from moving the form.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: Property to lock form at run time by TS

TS
Thu Sep 09 15:13:03 CDT 2004

worked like a charm, thanks a lot


"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:e0HBm5ckEHA.3392@TK2MSFTNGP15.phx.gbl...
> * "TS" <manofsteele@311.com> scripsit:
> > I can't find a property to lock the form so that you can't drag it
around by
> > the title bar. The locked property doensn't do this.
>
> From my FAQ (<URL:http://dotnet.mvps.org/dotnet/faqs/>):
>
> Based on an implementation written by Tom Spink.
>
> The code below defines a base class that provides a 'Moveable' property.
> By inheriting from this class and setting the 'Moveable' property to
> 'False', the user will be prevented from moving then form:
>
> \\\
> Imports System.ComponentModel
> Imports System.Windows.Forms
>
> Public Class MoveableForm
> Inherits Form
>
> Private Const WM_NCLBUTTONDOWN As Int32 = &HA1
> Private Const WM_SYSCOMMAND As Int32 = &H112
>
> Private Const HTCAPTION As Int32 = &H2
>
> Private Const SC_MOVE As Int32 = &HF010
>
> Private m_Moveable As Boolean
>
> Public Sub New()
> MyBase.New()
> Me.Moveable = True
> End Sub
>
> < _
> Category("Behavior"), _
> Description("Allows the form to be moved.") _
> > _
> Public Property Moveable() As Boolean
> Get
> Return m_Moveable
> End Get
> Set(ByVal Value As Boolean)
> m_Moveable = Value
> End Set
> End Property
>
> Protected Overrides Sub WndProc(ByRef m As Message)
> If Not m_Moveable Then
> If _
> m.Msg = WM_SYSCOMMAND And _
> m.WParam.ToInt32() = SC_MOVE _
> OrElse _
> m.Msg = WM_NCLBUTTONDOWN And _
> m.WParam.ToInt32() = HTCAPTION _
> Then
> Return
> End If
> End If
> MyBase.WndProc(m)
> End Sub
> End Class
> ///
>
> --
> M S Herfried K. Wagner
> M V P <URL:http://dotnet.mvps.org/>
> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>