Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Resize form w/out border

404 views
Skip to first unread message

Ryan Joseph So

unread,
Jan 12, 2005, 9:30:41 PM1/12/05
to
Hi,

I have a form which its FormBorderStyle property is set To NONE. My
problem is during run-time I can't resize it using my mouse. Is there a
way to resize it by not changing its FormBorderStyle suring run-time?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Robby

unread,
Jan 13, 2005, 3:34:29 AM1/13/05
to

I think you will have to write your own resize handler using Form.MouseDown
and Form.MouseUp events. On MouseDown you can check if the mouse is in a
corner of the form and save its screen position. On MouseUp you can compare
the mouse's current screen position with the MouseDown positon and resize
the form accordingly.

Robby

"Ryan Joseph So" <achill...@hotmail.com> wrote in message
news:%23xMFhfR%23EHA...@tk2msftngp13.phx.gbl...

Claes Bergefall

unread,
Jan 13, 2005, 4:37:04 AM1/13/05
to
Something like this will do it:

Private Const HTCAPTION As Integer = 2
Private Const HTLEFT As Integer = 10
Private Const HTRIGHT As Integer = 11
Private Const HTTOP As Integer = 12
Private Const HTTOPLEFT As Integer = 13
Private Const HTTOPRIGHT As Integer = 14
Private Const HTBOTTOM As Integer = 15
Private Const HTBOTTOMLEFT As Integer = 16
Private Const HTBOTTOMRIGHT As Integer = 17
Private Const WM_NCHITTEST As Integer = &H84

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_NCHITTEST Then
Dim pt As New Point(m.LParam.ToInt32)
pt = Me.PointToClient(pt)
If pt.X < 5 AndAlso pt.Y < 5 Then
m.Result = New IntPtr(HTTOPLEFT)
ElseIf pt.X > (Me.Width - 5) AndAlso pt.Y < 5 Then
m.Result = New IntPtr(HTTOPRIGHT)
ElseIf pt.Y < 5 Then
m.Result = New IntPtr(HTTOP)
ElseIf pt.X < 5 AndAlso pt.Y > (Me.Height - 5) Then
m.Result = New IntPtr(HTBOTTOMLEFT)
ElseIf pt.X > (Me.Width - 5) AndAlso pt.Y > (Me.Height - 5) Then
m.Result = New IntPtr(HTBOTTOMRIGHT)
ElseIf pt.Y > (Me.Height - 5) Then
m.Result = New IntPtr(HTBOTTOM)
ElseIf pt.X < 5 Then
m.Result = New IntPtr(HTLEFT)
ElseIf pt.X > (Me.Width - 5) Then
m.Result = New IntPtr(HTRIGHT)
Else
MyBase.WndProc(m)
End If
Else
MyBase.WndProc(m)
End If
End Sub

Change the coordinates to something that is appropriate for you
(the code above uses a "border" that is 5 pixels wide)
If you want to be able to drag the window you can return HTCAPTION

/claes


"Ryan Joseph So" <achill...@hotmail.com> wrote in message

news:#xMFhfR#EHA....@tk2msftngp13.phx.gbl...

Ryan Joseph So

unread,
Jan 13, 2005, 8:35:57 PM1/13/05
to
Hi Claes,

Thank you very much for the quick reply and for the codes. This is all I
need.

Ryan Joseph So

unread,
Jan 13, 2005, 8:36:03 PM1/13/05
to
Thanks for the info.
0 new messages