将边框添加到可滚动组件

时间:2013-01-16 00:15:36

标签: vb.net

我从System.Windows.Forms.ScrollableControl派生了一个组件,我在添加border属性时遇到了问题。我试过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

2 个答案:

答案 0 :(得分:0)

看起来你想要一个true / false的border属性:

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有一篇关于此事的文章:Adding a standard border to a control

答案 1 :(得分: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

结束地区