Movable property...

  • Thread starter Thread starter Hello
  • Start date Start date
H

Hello

Hello,

How to prevent user from moving the form at run time. At
the same time, I want to keep my control box and form
border.

Thanks,
Douglas ^^
 
Douglas,
This works for me
\\\\\\\\
Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Move
MyBase.Location = New System.Drawing.Point(30, 30)
End Sub
/////////
Cor
 
You'll have to create a new class which inherits from form, then make all
your forms inherit from this new form. Here is the class:

<WatchForWrapping>

Public Class MovableForm
Inherits System.Windows.Forms.Form

Private m_blnMovable As Boolean

Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const HTCAPTION As Integer = &H2
Private Const SC_MOVE As Integer = &HF010

Public Sub New()
MyBase.New()
m_Movable = True
End Sub

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

Protected Overrides Sub WndProc(ByRef m As Message)

If Not m_blnMovable Then
If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32 = SC_MOVE Then
Return
If m.Msg = WM_NCLBUTTONDOWN And m.WParam.ToInt32 = HTCAPTION
Then Return
End If

MyBase.WndProc(m)

End Sub
End Class

</WatchForWrapping>

This adds a Movable property to your form. Set it to false and the form
cannot be moved. The property will appear in the property browser under the
'Behavior' section. Remember: The forms you would like to have this property
must inherit from MovableForm, and the project must be built after you
create this class before your forms can inherit from it. Go into the code
and change the Inherits line of your form. Just to be safe, build your
project then view the form in the Designer, and play with your Movable
property.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
Hi Tom,

Nice one, I reckon I can use that sometime - It's going into my
snippets collection. Thanks.

What is the tag <WatchForWrapping> </WatchForWrapping> for ?
You've used it before I seem to remember.

Regards,
Fergus
 
OE will wrap lines to 78 chars when posting a response, so anything enclosed
in <WatchForWrapping> tags should be looked at to make sure a line hasn't
wrapped, or if it has to correct piece the line back together.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
Thanks Tom,

Wouldn't it be nice to have a tag to tell OE <not> to wrap.

And to have OE not flag for attention my own posts

And to have OE....

Regards,
Fergus
 
Hello,

Fergus Cooney said:
Nice one, I reckon I can use that sometime - It's going into my
snippets collection. Thanks.

I *hate* unmoveable windows.
What is the tag <WatchForWrapping> </WatchForWrapping> for ?
You've used it before I seem to remember.

Depending on the settings of the newsreader sending the message, text will
be automatically wrapped aftet ~80 characters.

Regards,
Herfried K. Wagner
 
I *hate* unmoveable windows.

So do I, but I love programming ;-)
Depending on the settings of the newsreader sending the message, text will
be automatically wrapped aftet ~80 characters.

I found a setting for this in OE, to wrap text after 'n' characters

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
Hi Herfried,

|| I *hate* unmoveable windows.

When I've finished KillerApp 2000 (due for release in 2006). I'll
be adding some special code to detect when it's your machine. It'll
let you move the window anywhere you like, but when you run it again,
it'll have forgotten. Haha.

Doh!, silly me, that's already standard behaviour these days.

|| I *hate* unmoveable windows.

Me too, but I think there may be a place for Tom's snippet in an
MDI app. ??

Regards,
Fergus.
 
I love programming too.
;-)
Ditto.

I know about this setting, but I do not change its value (currently 76
characters).

Ditto.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
Hi Tom,

|| Hey, that was written fresh this morning from memory.
|| I tested it out about 2 minutes before I went to work.

??

What's that got to do with using your ideas in an MDI app?

Regards,
Fergus
 
Back
Top