【问题标题】:How to make a control resizable by the user at runtime [.NET Winforms]?如何使用户在运行时 [.NET Winforms] 可调整控件的大小?
【发布时间】:2010-12-20 19:30:06
【问题描述】:

它在 Winforms 中。

我有一个固定在 TOP、BOTTOM 和 LEFT 的 UserControl。我想允许用户以某种方式拖动其右边框并水平调整其大小。

控件直接放在表单中,没有面板或组框可以放置“拆分器”。

知道如何让用户在运行时调整控件的大小吗?

【问题讨论】:

    标签: .net winforms custom-controls


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2020-11-22
      • 2010-10-30
      • 1970-01-01
      相关资源
      最近更新 更多