.net – 如何为多行文本框实现花式滚动条?

我想为多行文本框实现一个花哨的滚动条,如下图所示:

那个花哨的滚动条的任何想法?

P / S:我想要vb.net解决方案.

如果花哨的滚动条可以实现为另一个控件(您的图像实际上看起来像这样),这里是支持自定义滚动的ListBox代码
Imports System.Runtime.InteropServices

Public Class CustomScrollListBox
    Inherits ListBox

    Public Sub Scroll(ByVal percentage As Single)
        If (percentage < 0.0!) Then
            Throw New ArgumentException(nothing,"percentage")
        End If

        ' Sends the scroll / set position Windows message
        Const WM_VSCROLL As Integer = &H115
        Const SB_THUMBPOSITION As Integer = 4
        Dim wp As Integer = CInt(((percentage * MyBase.Items.Count) * 65536.0!)) + SB_THUMBPOSITION
        CustomScrollListBox.SendMessage(MyBase.Handle,WM_VSCROLL,New IntPtr(wp),IntPtr.Zero)
    End Sub

    <DllImport("user32.dll")> _
    Private Shared Function SendMessage(ByVal hWnd As IntPtr,ByVal msg As Integer,ByVal wParam As IntPtr,ByVal lParam As IntPtr) As IntPtr
    End Function

    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            ' Removes the vertical scroll window style
            Dim p As CreateParams = MyBase.CreateParams
            Const WS_VSCROLL As Integer = &H200000
            p.Style = (p.Style And -WS_VSCROLL)
            Return p
        End Get
    End Property

End Class

这是一个使用它的示例表单.我已将自定义滚动条实现为标准的Trackbar(trackBar1),例如:

Public Class Form1

    Private trackBar As TrackBar
    Private listBox As CustomScrollListBox

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        ' initialize some listBox props
        listBox = New CustomScrollListBox
        listBox.Location = New Point(&H19,210)
        listBox.Name = "listBox2"
        listBox.Size = New Size((&H17D - Me.TrackBar1.Width),&HAD)
        listBox.TabIndex = 1
        MyBase.Controls.Add(listBox)

       ' add some items
        Dim i As Integer
        For i = 0 To 100 - 1
            listBox.Items.Add(("item" & i))
        Next i

    End Sub


    Private Sub TrackBar1_Scroll(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        ' compute trackbar's position as a percentage
        listBox.Scroll(CSng(TrackBar1.Maximum - TrackBar1.Value) / TrackBar1.Maximum - TrackBar1.Minimum)
    End Sub

End Class

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...