2009-11-26 3 views
0

Winforms에 있습니다.런타임에 사용자가 컨트롤을 크기를 조절할 수있게 만드는 방법 [.NET Winforms]?

저는 TOP, BOTTOM 및 LEFT에 고정 된 UserControl을 보유하고 있습니다. 사용자가 어떻게 든 오른쪽 테두리를 드래그하여 수평으로 크기를 조정할 수있게하려고합니다.

컨트롤은 폼이나 "스플리터"를 배치 할 그룹 상자없이 배치됩니다.

런타임에 사용자가 컨트롤을 크기를 조정하는 방법을 알려주십시오.

답변

1
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 
관련 문제