¿Cómo hacer que un usuario pueda cambiar el control en tiempo de ejecución [.NET Winforms]?

StackOverflow https://stackoverflow.com/questions/1805686

  •  05-07-2019
  •  | 
  •  

Pregunta

Está en Winforms.

Tengo un UserControl que está anclado TOP, BOTTOM y LEFT. Me gustaría permitir que el usuario arrastre su borde derecho de alguna manera y cambie su tamaño horizontalmente.

El control se coloca directamente en el formulario, sin panel o cuadro de grupo para colocar un "Divisor".

¿Alguna idea de cómo el usuario puede cambiar el tamaño de un control en tiempo de ejecución?

¿Fue útil?

Solución

Private Declare Function GetWindowLongA Lib "User32" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
Private Declare Function SetWindowLongA Lib "User32" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal CX As Integer, ByVal CY As Integer, ByVal wFlags As Integer)
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
Const SWP_NOMOVE = &H2
Const SWP_DRAWFRAME = &H20
Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ResizeControl(TextBox1, Me)
End Sub

Sub ResizeControl(ByVal ControlName As Control, ByVal FormName As Form)
    Dim NewStyle As Long
    NewStyle = GetWindowLongA(ControlName.Handle, GWL_STYLE)
    NewStyle = NewStyle Or WS_THICKFRAME
    NewStyle = SetWindowLongA(ControlName.Handle, GWL_STYLE, NewStyle)
    SetWindowPos(ControlName.Handle, FormName.Handle, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME)
End Sub
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top