Using scrollbars

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Using scrollbars
MrAksel
Hey what is the code for scrollbars both V and H for scrolling a panel or something else like in a listbox or a multiline textbox?
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Using scrollbars
mandai
This would switch selected items in a listbox:
Code: Select all
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        HScrollBar1.LargeChange = 1
        HScrollBar1.Maximum = ListBox1.Items.Count - 1
    End Sub

    Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
        ListBox1.SelectedIndex = HScrollBar1.Value
    End Sub
And this would scroll lines in a textbox:
Code: Select all
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        VScrollBar1.LargeChange = 1
    End Sub

    Private Sub VScrollBar1_Scroll_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
        If TextBox1.Text.Length > 0 Then
            Dim lineStarts As List(Of Integer) = New List(Of Integer)

            For i As Integer = 0 To TextBox1.Text.Length - 2
                If TextBox1.Text.Substring(i, 2) = vbCrLf Then
                    lineStarts.Add(i)
                End If
            Next

            VScrollBar1.Maximum = lineStarts.Count
            If VScrollBar1.Value < lineStarts.Count Then
                TextBox1.SelectionStart = lineStarts(VScrollBar1.Value)
            Else
                TextBox1.SelectionStart = TextBox1.Text.Length
            End If
            TextBox1.ScrollToCaret()
        End If
    End Sub
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Using scrollbars
MrAksel
Dude thanks!! You own at coding :!!!!
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: Using scrollbars
GoodGuy17
Please lock this topic Aksel.
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Using scrollbars
Axel
Looks like this isn't closed yet. xD
http://vagex.com/?ref=25000
5 posts Page 1 of 1
Return to “Tutorial Requests”