I been at this for to long so I will give somebody else a shot at this.

I have a text box that has a string in it that I will use for a SQL statement. Under the text box I have two trackbar controls.

I want to be able to slide the left trackbar and trim characters from the left of the string and same for the right side.

So say my string is "DALLAS" if I move the left track bar 3 spots I end up with "LAS" then I can move the right track bar 1 spot and end up with "LA".

Also I want to be able to move the sliders back and rebuild the string (that is were its getting tricky for me).

Maybe its not even possible since I have to rest the max values of the trackbar and I won't be able to rebuild the string?

you could set the TextBox1.Tag property to the orginal string.
If a user now use the trackbars you display the manipulation in the textbox1. so the orginal string never changes.

Yes I have the original string, problem is the parsing and reseting the max values of the trackbar. This works close but not quite.

---- in the right scroll event
textbox1.Text = Strings.Right(textbox1.Text, Len(textbox1.Text) - 1)
tbRight.Maximum = Len(textbox1.Text) + 1

--- in the left scroll event
textbox1.Text = Strings.Left(textbox1.Text, Len(textbox1.Text) - 1)
tbLeft.Maximum = Len(txtMfg.Text) + 1

It was a fun little project until I couldn't get it to work. lol.

Here you go:

Public Class Form1
    'store originally typed string
    Dim originalString As String
    'boolean to check if textchange is result of scroll
    Dim scrolled As Boolean = False

    'current trackbar values
    Dim currentLeft As Integer
    Dim currentRight As Integer

    Private Sub txtReduceString_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtReduceString.TextChanged
        'if text changed by user reset values
        If Not scrolled Then
            'store value entered by user
            originalString = txtReduceString.Text
            'adjust track bar maximums
            tbLeft.Maximum = txtReduceString.Text.Length - 1
            tbRight.Maximum = txtReduceString.Text.Length - 1
            'initialise variables
            currentLeft = 0
            tbLeft.Value = 0
            currentRight = 0
            tbRight.Value = 0
        Else
            'if text changed by scroll ignore textchange and reset scrolled variable
            scrolled = False
        End If
    End Sub

    Private Sub tbLeft_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbLeft.Scroll
        'update boolean to show trackbar was scrolled
        scrolled = True

        'prevent trackbars from overlapping
        If tbLeft.Value < originalString.Length - currentRight Then
            'if new value does not cause overlap then store it and update textbox
            currentLeft = tbLeft.Value
            ReduceText()
        Else
            'if new value overlaps then prevent scroll
            tbLeft.Value = currentLeft
        End If

    End Sub

    Private Sub tbRight_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbRight.Scroll
        'update boolean to show trackbar was scrolled
        scrolled = True

        'prevent trackbars from overlapping
        If tbRight.Value < originalString.Length - currentLeft Then
            'if new value does not cause overlap then store it and update textbox
            currentRight = tbRight.Value
            ReduceText()
        Else
            'if new value overlaps then prevent scroll
            tbRight.Value = currentRight
        End If
    End Sub

    Private Sub ReduceText()
        'use values set by tracbar to reduce string
        'start at character determined by currentLeft
        'length determined by full length of string, less starting point, less value of currentRight
        txtReduceString.Text = originalString.Substring(currentLeft, (originalString.Length - currentLeft) - currentRight)
    End Sub
End Class

I created a form with a textbox and two trackbars:
Textbox:
.name = txtReduceString
.TextAlign = Center
.TextChanged += txtReduceString_TextChanged

TrackBar1:
.name = tbLeft
.Maximum = 0
.Scroll += tbLeft_Scroll

TrackBar2:
.name = tbRight
.Maximum = 0
.RightToLeft = Yes
.Scroll + tbRight_Scroll

commented: Quick response and written very well to understand. Thanks for donating your time to help my problem Ryshad! +1

Wow, that works amazing. Thank you so much for taking the time out to help me with this. It is much appriciated. I been trying for hours to get this to work so you are a life saver. Thank you again!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.