DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Control a TrackBar

  1. #1
    Join Date
    Dec 2006
    Posts
    12

    Control a TrackBar

    Does anyone know how to control the Value of a TrackBar with the Value of a TextBox? So I can type a # into the textbox and have the trackbar go to that position.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try this:
    Code:
    Private Sub TextBox1_KeyPress(ByVal sender As Object, _
        ByVal e As KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then
            UpdateTrackbar()
        End If
    End Sub
    
    Private Sub TextBox1_LostFocus(ByVal sender As Object, _
        ByVal e As EventArgs) Handles TextBox1.LostFocus
        UpdateTrackbar()
    End Sub
    
    Private Sub UpdateTrackbar()
        Dim value As Integer = CInt(Val(TextBox1.Text))
        If value > TrackBar1.Maximum Then
            value = TrackBar1.Maximum
        ElseIf value < TrackBar1.Minimum Then
            value = TrackBar1.Minimum
        End If
        TrackBar1.Value = value
    End Sub
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Dec 2006
    Posts
    12
    Phil,

    Sorry to ask but I am rather new to VB so this code should set the track bar to the Textbox1's value when you hit enter..also could you please explain why the LostFocus sub is for..Thanks for your help this is for a bluetooth Motor Speed control project for a robot. I already have the Slider Bar setting the speed but I wanted to be able to set to position with text because speach control is next on my list. Thanks again

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    The code I posted will set the trackbar to the value in the textbox both when the user presses the Enter key (that's what the KeyPress handler is for) and when he tabs out of the textbox (that's what the LostFocus handler is for).
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Dec 2006
    Posts
    12
    Phil,
    Thanks again for your help it works great.

Similar Threads

  1. DockableWindow .NET Control Released
    By Actipro Software Support in forum dotnet.announcements
    Replies: 0
    Last Post: 02-11-2002, 02:33 PM
  2. Replies: 15
    Last Post: 05-09-2001, 04:40 AM
  3. getting the name of the application that contains my control
    By Floyd McDonald in forum VB Classic
    Replies: 1
    Last Post: 03-30-2001, 03:17 AM
  4. WEIRD ActiveX control problem
    By Glenn in forum ASP.NET
    Replies: 0
    Last Post: 12-13-2000, 08:55 AM
  5. Replies: 0
    Last Post: 03-23-2000, 05:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center