2011年7月9日土曜日

→→→スクロール

ListBox が 2つ出現して片方のスクロールバーを移動させると
もう片方も同じ動きをする

Private Class MyListBox
         Inherits  ListBox
          Public Event Scroll()
           Protected Overrides Sub WndProc(Byref m As Message)
              const WM_VSCROLL As Integer = &H115I
              If m.msg = VM_VSCROLL Then
                   RaiseEvent Scroll()
              End If
              MyBase.WndProc(m)
          End Sub
End Class

Private WithEvents MyListBox1, MyListBox2 As New MyListBox()

Private Sub Form1_Load( ......
          SuspendLayout()
          MyListBox1.Name  = "MyListBox1"
          MyListBox2.Name  = "MyListBox2"
          MyListBox1.Size = New size( 200 , 300 )
          MyListBox2.Size = New size( 200 , 300 )
          MyListBox1.Location = New point( 40 , 40 )
          MyListBox2.Location = New point( 250 , 40 )
          'ダミーデータの作成
          Dim R As New Random()
          Dim I  As Integer
          For I = 1 To 100
                MyListBox1.Items.Add( New String ( "*"c , R.Next( 1 , 20 )))
                MyListBox2.Items.Add( New String ( "@"c , R.Next( 1 , 20 )))
          Next
          Me.Controls.Add(MyListBox1)
          Me.Controls.Add(MyListBox2)
End Sub

'スクロールの同期
Private Sub MyListBox1_Scroll() Handles MyListBox1.Scroll
        MyListBox2.TopIndex = MyListBox1.TopIndex
End Sub

Private Sub MyListBox2.Scroll() Handles MyListBox2.Scroll
        MyListBox1.TopIndex = MyListBox2.TopIndex
End Sub

0 件のコメント:

コメントを投稿