Resize form w/out border

  • Thread starter Thread starter Ryan Joseph So
  • Start date Start date
R

Ryan Joseph So

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?
 
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
 
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
 
Hi Claes,

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