Resize windows without borders in one method.

Discussion in 'Programming General' started by Flaming Idiots, Mar 4, 2007.

Resize windows without borders in one method.
  1. Unread #1 - Mar 4, 2007 at 7:51 AM
  2. Flaming Idiots
    Joined:
    Dec 22, 2005
    Posts:
    235
    Referrals:
    1
    Sythe Gold:
    0
    Two Factor Authentication User

    Flaming Idiots Active Member
    Visual Basic Programmers

    Resize windows without borders in one method.

    How it works:

    What it does is modify the result of the windows method WM_NCHITTEST.
    So if it is within 3 pixels of the edge of the form, it will tell the form to allow resizing, and if it within 20 pixels of the top, it will let you drag the form.

    How to use it:

    Just add the following code into your form, and make sure your form has no border.
    Code:
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            MyBase.WndProc(m)
            If m.Msg = 132 And Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None Then
                Dim z As Point = Control.MousePosition
                If Me.Parent IsNot Nothing Then z -= Me.Parent.PointToScreen(New Point())
                Static ResizePadding As New Padding(3)
                Dim Result As Integer = 0
                Select Case z.X
                    Case Is < Left + ResizePadding.Left : Result = 10
                    Case Is > Right - ResizePadding.Right : Result = 11
                End Select
                Select Case z.Y
                    Case Is < Top + ResizePadding.Top
                        Select Case Result
                            Case 0 : Result = 12
                            Case 10 : Result = 13
                            Case 11 : Result = 14
                        End Select
                    Case Is < Top + 20
                        Select Case Result
                            Case 0 : Result = 2
                        End Select
                    Case Is > Bottom - ResizePadding.Bottom
                        Select Case Result
                            Case 0 : Result = 15
                            Case 10 : Result = 16
                            Case 11 : Result = 17
                        End Select
                End Select
                If Result <> 0 Then m.Result = Result
            End If
        End Sub
     
< does this work? | image button >

Users viewing this thread
1 guest


 
 
Adblock breaks this site