This is a migrated thread and some comments may be shown as answers.

HScrollbar behave like NumericUpandDown?

1 Answer 43 Views
ScrollBar
This is a migrated thread and some comments may be shown as answers.
Web
Top achievements
Rank 1
Web asked on 08 Dec 2006, 09:24 PM
I am looking for a Control which behaves like the Numeric UPAndDown Control. Would be there any way to get the HScrollbar working like it or do you have any other suggestions?
thank you

1 Answer, 1 is accepted

Sort by
0
Angel
Telerik team
answered on 11 Dec 2006, 02:21 PM

Hi Kerstin,

HScrollBar and VScrollBar cannot be used directly as the control you need. However, you can achieve similar behavior with a few lines of code:

1. Hide the scroll thumb.

    this.radHScrollBar1 = new Telerik.WinControls.UI.RadHScrollBar();
    ...
    this.radHScrollBar1.ScrollBarElement.Children[4].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;


2. If the user clicks in the area between the two scroll buttons LargeScroll events will be raised (Page Up/Down for vertical scroll or Page Left/Right for horizontal scroll). You can handle the "Scroll" and the "ValueChanged" events to disable this behavior.

        private bool largeValueChanging = false;
        private int oldValue;

        private void radHScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            if (e.Type == ScrollEventType.LargeDecrement || e.Type == ScrollEventType.LargeIncrement)
            {
                this.largeValueChanging = true;
                RadScrollBar scrollBar = (RadScrollBar)sender;
                this.oldValue = e.OldValue;
            }
        }

        private void radHScrollBar1_ValueChanged(object sender, EventArgs e)
        {
            if (this.largeValueChanging)
            {
                this.largeValueChanging = false;
                RadScrollBar scrollBar = (RadScrollBar)sender;
                scrollBar.Value = this.oldValue;
            }
        }

Let us know if you experience any problems with this approach.


Kind regards,
Angel
the telerik team
Tags
ScrollBar
Asked by
Web
Top achievements
Rank 1
Answers by
Angel
Telerik team
Share this question
or