none
Trackbar 0.5 SmallChange RRS feed

  • Question

  • Hi,

    I am using a Trackbar in my C# application. It's from DevExpress but i guess the standard one is the same..

    It uses 1 as minimum SmallChange but I want the value to be 1, 1.5, 2, 2.5, 3, 3.5, etc...

    How can I do this?
    Tuesday, March 5, 2013 1:11 PM

Answers

  • multiplying by 2? sorry I didn't get it... any example please...?

    Let's say that the only values you want your TrackBar to have are 1, 1.5, 2, 2.5, 3, 3.5 and 4. You can't do that because the Value has to be an Integer.  My suggestion is to set the Minimum property to 2 instead of 1, the Maximum property to 8 instead of 4 and the SmallChange property to 1 instead of 0.5.  The Value property of the TrackBar is always twice what you intended it to be.  If you want to set the Value to 2.5, set it to 5 instead.  If you read the Value of the TrackBar and it is 7, divide 7 by 2 to get the value you really wanted it to be (3.5).

    myTrackBar.Minimum = 2
    myTrackBar.Maximum = 8
    myTrackBar.SmallChange = 1
    
    Dim myValue As Decimal = 2.5D
    myTrackBar.Value = CInt(myvalue * 2) 'Set value
    
    Dim newValue As Decimal = myTrackBar.Value / 2 'Read value

    Tuesday, March 5, 2013 3:18 PM

All replies

  • The .Net TrackBar value (and the SmallChange property) has to be an integer.  If the same applies to the DevExpress control, you can get the same effect as using half values (1.5, 2.5, 3.5 etc) by just multiplying the values by 2 so that they become whole numbers.  Don't forget to multiply the maximum and minimum values by 2 as well.
    • Edited by Blackwood Tuesday, March 5, 2013 2:43 PM
    Tuesday, March 5, 2013 1:42 PM
  • multiplying by 2? sorry I didn't get it... any example please...?

    Tuesday, March 5, 2013 3:04 PM
  • multiplying by 2? sorry I didn't get it... any example please...?

    Let's say that the only values you want your TrackBar to have are 1, 1.5, 2, 2.5, 3, 3.5 and 4. You can't do that because the Value has to be an Integer.  My suggestion is to set the Minimum property to 2 instead of 1, the Maximum property to 8 instead of 4 and the SmallChange property to 1 instead of 0.5.  The Value property of the TrackBar is always twice what you intended it to be.  If you want to set the Value to 2.5, set it to 5 instead.  If you read the Value of the TrackBar and it is 7, divide 7 by 2 to get the value you really wanted it to be (3.5).

    myTrackBar.Minimum = 2
    myTrackBar.Maximum = 8
    myTrackBar.SmallChange = 1
    
    Dim myValue As Decimal = 2.5D
    myTrackBar.Value = CInt(myvalue * 2) 'Set value
    
    Dim newValue As Decimal = myTrackBar.Value / 2 'Read value

    Tuesday, March 5, 2013 3:18 PM