1

I had a problem when Minimize and maximize the program from the taskbar icon . Where is the form without Border? When I put the code to Minimize and maximize the program from the taskbar icon , it works without problems. When I put the form extension code in all direction with Minimize and maximize code, the form extension code does not work, but only Minimize and maximize works.

Extension code: I mean increasing the width and height of the form by dragging the mouse from the edge inward or outward.

'Minimize and maximize the program from the taskbar icon form 
   Protected Overrides ReadOnly Property CreateParams As CreateParams
        Get
            Dim CPa As CreateParams = MyBase.CreateParams
            CPa.Style = CPa.Style Or &HA0000

            Return (CPa)
        End Get
    End Property

'form extension

 Private Const WM_NCHITTEST As Integer = &H84
    Private Const WM_MOUSEMOVE As Integer = &H200
    Private Const WM_LBUTTONDOWN As Integer = &H201
    'Private Const WM_LBUTTONUP As Integer = &H202
    Private Const MK_LBUTTON As Integer = &H1
    Private Const HTLEFT As Integer = &HA
    Private Const HTRIGHT As Integer = &HB
    Private Const HTTOP As Integer = &HC
    Private Const HTTOPLEFT As Integer = &HD
    Private Const HTTOPRIGHT As Integer = &HE
    Private Const HTBOTTOM As Integer = &HF
    Private Const HTBOTTOMLEFT As Integer = &H10
    Private Const HTBOTTOMRIGHT As Integer = &H11
    Private OffSet As Point = Point.Empty


    Protected Overrides Sub WndProc(ByRef m As Message)
        If m.Msg = WM_NCHITTEST Then
            Dim loc As New Point(m.LParam.ToInt32 And &HFFFF, m.LParam.ToInt32 >> 16)
            loc = PointToClient(loc)
            Dim bTop As Boolean = (loc.Y < ClientRectangle.Y + 4)
            Dim bLeft As Boolean = (loc.X < ClientRectangle.X + 4)
            Dim bRight As Boolean = (loc.X > Width - 4)
            Dim bBottom As Boolean = (loc.Y > Height - 4)
            If bTop AndAlso bLeft Then
                m.Result = CType(HTTOPLEFT, IntPtr)
                Return
            ElseIf bTop AndAlso bRight Then
                m.Result = CType(HTTOPRIGHT, IntPtr)
                Return
            ElseIf bBottom AndAlso bLeft Then
                m.Result = CType(HTBOTTOMLEFT, IntPtr)
                Return
            ElseIf bBottom AndAlso bRight Then
                m.Result = CType(HTBOTTOMRIGHT, IntPtr)
                Return
            ElseIf bLeft Then
                m.Result = CType(HTLEFT, IntPtr)
                Return
            ElseIf bTop Then
                m.Result = CType(HTTOP, IntPtr)
                Return
            ElseIf bRight Then
                m.Result = CType(HTRIGHT, IntPtr)
                Return
            ElseIf bBottom Then
                m.Result = CType(HTBOTTOM, IntPtr)
                Return
            End If
        ElseIf m.Msg = WM_LBUTTONDOWN Then
            OffSet = New Point(MousePosition.X - Me.Location.X, MousePosition.Y - Me.Location.Y)
        ElseIf m.Msg = WM_MOUSEMOVE AndAlso m.WParam.ToInt32 = MK_LBUTTON Then
            Me.Location = New Point(MousePosition.X - OffSet.X, MousePosition.Y - OffSet.Y)
        End If
        MyBase.WndProc(m)
    End Sub

fast2021
  • 115
  • 1
  • 9
  • Fix1: `CPa.Style = CPa.Style Or &HA0000`. Fix2: Use `AndAlso` in `If` statements instead of `And`. – dr.null Jun 19 '21 at 17:43
  • hi dr.null what means Fix2: Use AndAlso in If statements instead of And. –???? – fast2021 Jun 19 '21 at 19:00
  • 1
    Ex, `If bTop AndAlso bLeft Then ...` instead of `If bTop And bLeft Then ...`. See [this](https://stackoverflow.com/questions/302047/what-is-the-difference-between-and-and-andalso-in-vb-net) for more. – dr.null Jun 19 '21 at 19:55
  • I changed but nothing new happened – fast2021 Jun 19 '21 at 20:00
  • 1
    Replace `&HA0000` (WS_SYSMENU Or WS_MINIMIZEBOX) with `&H20000` (WS_MINIMIZEBOX). The `WS_SYSMENU` is the problem here and you don't need it. See [Window Styles](https://learn.microsoft.com/en-us/windows/win32/winmsg/window-styles). – dr.null Jun 20 '21 at 09:29

0 Answers0