2

我从中派生了一个组件,System.Windows.Forms.ScrollableControl但添加边框属性时遇到问题。我试过CreateParams但没有成功,也许我错过了什么?

Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
    Get
        Dim params As CreateParams = MyBase.CreateParams
        params.Style = params.Style Or &H800000 ' Turn on WS_BORDER
        Return params
    End Get
End Property

 'disable scroll bars, this part also disables my border
Protected Overrides Sub DefWndProc(ByRef m As Message)
    If m.Msg <> 131 Then
        MyBase.DefWndProc(m)
    End If
End Sub
4

2 回答 2

0

看起来你想要一个真/假的边框属性:

Protected Overrides ReadOnly Property CreateParams() As CreateParams
  Get
    Dim params As CreateParams = MyBase.CreateParams
    If _Border Then
      params.Style = params.Style Or &H800000 ' Turn on WS_BORDER
    End If
    Return params
  End Get
End Property

Private _Border As Boolean = False

Property Border() As Boolean
  Get
    Return _Border
  End Get
  Set(ByVal value As Boolean)
    _Border = value
    Me.RecreateHandle()
    Me.Invalidate()
  End Set
End Property

Bob Powell 有一篇关于此的文章:向控件添加标准边框

于 2013-01-16T00:25:53.383 回答
0

好的,解决了没有滚动条和漂亮的标准边框属性一起:) 这是代码,以防万一有人需要:

区域“禁用滚动条”

<DllImport("user32.dll")> _
Private Shared Function ShowScrollBar(ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Integer) As Integer
End Function

Protected Overrides Sub DefWndProc(ByRef m As Message)
    If m.Msg = 131 Then

        ShowScrollBar(m.HWnd, 3, 0)

    End If

    MyBase.DefWndProc(m)
End Sub

结束区域

于 2013-01-16T10:23:13.380 回答