Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Vb.net - Ridimensionare una form via codice

    Ciao a tutti.
    Ho una form senza bordi e vorrei che quando con il mouse mi sposto sull'angolo destro in basso della stessa mi desse la possibilità di ridimensionarla.

    Qualcuno sa dirmi qual'è al strada migliore per farlo ed eventualmente spstaremi un codice di esempio?

    Grazie a tutti.

    Daniele

  2. #2
    Aggiungi al form il seguente codice:
    codice:
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Const WM_NCHITTEST As Integer = &H84
            Const HTCLIENT As Integer = 1
            Const HTTOP As Integer = 12
            Const HTTOPLEFT As Integer = 13
            Const HTTOPRIGHT As Integer = 14
            Const HTLEFT As Integer = 10
            Const HTRIGHT As Integer = 11
            Const HTBOTTOM As Integer = 15
            Const HTBOTTOMLEFT As Integer = 16
            Const HTBOTTOMRIGHT As Integer = 17
            Const borderWidth As Integer = 5
            MyBase.WndProc(m)
            If m.Msg = WM_NCHITTEST And m.Result.ToInt32 = HTCLIENT Then
                Dim p As New Drawing.Point(m.LParam.ToInt32 And &HFFFF, m.LParam.ToInt32 >> 16)
                p = Me.PointToClient(p)
                If p.X < borderWidth Then
                    If p.Y < borderWidth Then
                        m.Result = New IntPtr(HTTOPLEFT)
                    ElseIf p.Y + borderWidth > Me.Height Then
                        m.Result = New IntPtr(HTBOTTOMLEFT)
                    Else
                        m.Result = New IntPtr(HTLEFT)
                    End If
                ElseIf p.X + borderWidth > Me.Width Then
                    If p.Y < borderWidth Then
                        m.Result = New IntPtr(HTTOPRIGHT)
                    ElseIf p.Y + borderWidth > Me.Height Then
                        m.Result = New IntPtr(HTBOTTOMRIGHT)
                    Else
                        m.Result = New IntPtr(HTRIGHT)
                    End If
                ElseIf p.Y < borderWidth Then
                    m.Result = New IntPtr(HTTOP)
                ElseIf p.Y + borderWidth > Me.Height Then
                    m.Result = New IntPtr(HTBOTTOM)
                End If
            End If
    .
    In questo modo il form potrà essere ridimensionato normalmente. Se invece ti interessa solamente il codice per il ridimensionamento in basso a destra inserisci
    codice:
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Const WM_NCHITTEST As Integer = &H84
            Const HTCLIENT As Integer = 1
            Const HTBOTTOMRIGHT As Integer = 17
            Const borderWidth As Integer = 5
            MyBase.WndProc(m)
            If m.Msg = WM_NCHITTEST And m.Result.ToInt32 = HTCLIENT Then
                Dim p As New Drawing.Point(m.LParam.ToInt32 And &HFFFF, m.LParam.ToInt32 >> 16)
                p = Me.PointToClient(p)
                If p.X + borderWidth > Me.Width And p.Y + borderWidth > Me.Height Then
                    m.Result = New IntPtr(HTBOTTOMRIGHT)
                End If
            End If
        End Sub
    .
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Grazie infinite: era proprio quello che cercavo!

    Un saluto e buona settimana.

    Daniele

  4. #4
    Non c'è di che; ciao!
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.