掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
VB.netでリストの垂直スクロールを設定するには? (ID:114910)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
VB6 なら、 Private Sub List1_Scroll() List2.TopIndex = List1.TopIndex End Sub だけで済むのですが…VB.NETにはScorllに相当するイベントが 用意されていないので、WM_VSCROLLをとらえる必要があると思います。 ちょっと面倒ですね。(^^;) 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 = WM_VSCROLL Then RaiseEvent Scroll() End If MyBase.WndProc(m) End Sub Protected Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs) If e.Delta <> 0 Then RaiseEvent Scroll() End If End Sub Protected Overrides Sub OnSelectedIndexChanged(ByVal e As EventArgs) RaiseEvent Scroll() End Sub End Class Private WithEvents MyListBox1, MyListBox2 As New MyListBox() Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load SuspendLayout() 'カスタムListBoxの作成 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) ResumeLayout() 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
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.