locked
Trackbar, minimum value at the top RRS feed

  • Question

  • Hi, I need to use a trackbar as a scrollbar, but the problem is that the min value is at the bottom i need it to be 0 at the top and maxvalue at the bottom..
    Tuesday, November 1, 2011 1:49 PM

Answers

  • yeah, the problem with that is that I'm using http://www.codeproject.com/KB/miscctrl/gTrackBar.aspx

    Then you have direct access to the source, and there is no need to override.  Just adjust the code in the class you are using to invert the values in the same way that the example above does the inversion.

    Or, better still, add a property called "Invert" that, when set to True, implements the inversion.

    Wednesday, November 2, 2011 8:09 PM
  • I thought you meant Integer.MaxValue when talking about MaxValue. If Maximum is MyListBox1.Items.Count then use MyListBox1.Items.Count-Value.

    You should be able to get it work once you get the idea. As by design minimum<maximum if you want the other way round, the idea is that the trackbar value is not the value you want, but the value you have to subtract from the maximum to get the value you want (this way when the trackbar is 0 you get Maximum and when it is Maximum you get 0).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Tuesday, November 1, 2011 6:03 PM

All replies

  • Hi,

    Set Minimum to 0, Maximum to MaxValue, and use Integer.MaxValue-TrackBar.Value rather than just TrackBar.Value to get the value you want...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Tuesday, November 1, 2011 3:42 PM
  • Hi,

    Set Minimum to 0, Maximum to MaxValue, and use Integer.MaxValue-TrackBar.Value rather than just TrackBar.Value to get the value you want...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    wierd.. 

    with 

     

     

     Dim scval As Integer

        Private Sub GTrackBar3_ValueChanged(sender As System.Object, e As System.EventArgs) Handles GTrackBar3.ValueChanged

            Try

                scval = Integer.MaxValue - GTrackBar3.Value

                          MyListBox1.TopIndex = scval

            Catch ex As Exception

                wc(ex.Message)

            End Try

        End Sub

     

     

     

    the min value is 0 and the max value is mylistbox1.items.count
    when i print scval i get a insanely high value  for example 2147483629

    Tuesday, November 1, 2011 3:56 PM
  • I thought you meant Integer.MaxValue when talking about MaxValue. If Maximum is MyListBox1.Items.Count then use MyListBox1.Items.Count-Value.

    You should be able to get it work once you get the idea. As by design minimum<maximum if you want the other way round, the idea is that the trackbar value is not the value you want, but the value you have to subtract from the maximum to get the value you want (this way when the trackbar is 0 you get Maximum and when it is Maximum you get 0).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Tuesday, November 1, 2011 6:03 PM
  • I thought you meant Integer.MaxValue when talking about MaxValue. If Maximum is MyListBox1.Items.Count then use MyListBox1.Items.Count-Value.

    You should be able to get it work once you get the idea. As by design minimum<maximum if you want the other way round, the idea is that the trackbar value is not the value you want, but the value you have to subtract from the maximum to get the value you want (this way when the trackbar is 0 you get Maximum and when it is Maximum you get 0).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Thanks :) I will mark this as the answer soon, just one more thing, since the listbox can view 22 items at the time, and i use ListBox1.TopIndex i get some dead space at the end of it.. how can i get rid of that
    Tuesday, November 1, 2011 8:18 PM
  • Thanks :) I will mark this as the answer soon, just one more thing, since the listbox can view 22 items at the time, and i use ListBox1.TopIndex i get some dead space at the end of it.. how can i get rid of that
    Check the TopIndex value and make sure it is never greater than the item count - 22.
    Tuesday, November 1, 2011 11:03 PM
  • What do you mean?
    Tuesday, November 1, 2011 11:04 PM
  • I presume you are using the trackbar value to set the top index property of the list.  When you set the topindex property, check that it is not greater than the list item count - 22.  If it is greater than this value, set the top index to that value.

    You may be able to achieve a similar result by setting the trackbar maximum value to item count - 22.  It depends on how you want the list to respond to trackbar changes.

    Tuesday, November 1, 2011 11:12 PM
  • Hi swehunter2000,

     

    Go to the PROJECT menu and select Add Class...

    as in the following picture.>>

     

    In the Name Box type in NewTrackBar.Vb

    and then click on the ADD button as in the following picture.>>

     

    Then paste this code in:>>

     

    Public Class NewTrackBar
        Inherits System.Windows.Forms.TrackBar
    
        Public Shadows Property Value() As Integer
            Get
                Return Me.Maximum - MyBase.Value
            End Get
            Set(ByVal value As Integer)
                MyBase.Value = Me.Maximum - value
            End Set
        End Property
    
    End Class
    

     


    Next select BUILD from the BUILD menu ( which is usually the 1st item ).>>

     

    Photobucket

     

    Then you will see NewTrackBar in your ToolBox.>>

     



    Photobucket

     

    If you drop a NewTrackBar on your Form then zero will be at the top when the orientation is vertical.  :)

    Enjoy!!

    To test the above I tried the following Form1 code.>>

     

     

    Public Class Form1
    
        Private Sub NewTrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewTrackBar1.Scroll
    
            Me.Text = NewTrackBar1.Value.ToString
    
        End Sub
    
    End Class




    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.

    Wednesday, November 2, 2011 2:24 PM
  • yeah, the problem with that is that I'm using http://www.codeproject.com/KB/miscctrl/gTrackBar.aspx
    Wednesday, November 2, 2011 4:35 PM
  • yeah, the problem with that is that I'm using http://www.codeproject.com/KB/miscctrl/gTrackBar.aspx

    Then you have direct access to the source, and there is no need to override.  Just adjust the code in the class you are using to invert the values in the same way that the example above does the inversion.

    Or, better still, add a property called "Invert" that, when set to True, implements the inversion.

    Wednesday, November 2, 2011 8:09 PM
  • yeah, the problem with that is that I'm using http://www.codeproject.com/KB/miscctrl/gTrackBar.aspx

    Then you have direct access to the source, and there is no need to override.  Just adjust the code in the class you are using to invert the values in the same way that the example above does the inversion.

    Or, better still, add a property called "Invert" that, when set to True, implements the inversion.

    Hi Acamar,

     I really like that idea!!




    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.

    Thursday, November 3, 2011 1:29 AM