|
1 | | -# How-to-customize-the-range-intervals-in-Winforms-RangeSlider |
2 | | -The **Syncfusion WinForms RangeSlider** control provides an option to customize the range of the slider to meet specific application requirements. By adjusting properties such as **Minimum**, **Maximum**, **TickFrequency**, and **StartPosition**, you can create a slider that fits your desired range and layout. |
| 1 | +# How to Customize the Range Intervals in WinForms RangeSlider |
| 2 | +The Syncfusion WinForms RangeSlider control provides options to customize the slider range to meet specific application requirements. By adjusting properties such as Minimum, Maximum, TickFrequency, and handling the DrawLabel event, you can create a slider that fits your desired range and display format. |
3 | 3 |
|
4 | 4 | ## Why Customize the Range? |
5 | 5 | Customizing the range intervals allows you to: |
6 | 6 | - Define the minimum and maximum values for the slider. |
7 | 7 | - Control the tick frequency for precise value selection. |
8 | | -- Position the form appropriately for better user experience. |
| 8 | +- Display custom labels (e.g., time intervals) for better user experience. |
9 | 9 |
|
10 | 10 | ## Key Properties |
| 11 | + |
11 | 12 | - **Minimum**: Sets the lowest value of the slider. |
12 | 13 | - **Maximum**: Defines the highest value of the slider. |
13 | 14 | - **TickFrequency**: Determines the interval between ticks. |
| 15 | +- **ShowLabels**: Enables label display on the slider. |
14 | 16 | - **StartPosition**: Specifies the initial position of the form. |
15 | 17 |
|
16 | 18 | ## Example Code |
17 | | -```csharp |
18 | | -// To Customize the Range |
19 | | -this.rangeSlider1.Minimum = 1; |
20 | | -this.rangeSlider1.Maximum = 10; |
21 | | -this.rangeSlider1.TickFrequency = 1; |
22 | | -this.StartPosition = FormStartPosition.CenterScreen; |
23 | | -``` |
| 19 | +```C# |
| 20 | +public Form1() |
| 21 | +{ |
| 22 | + InitializeComponent(); |
| 23 | + |
| 24 | + // Configure RangeSlider properties |
| 25 | + this.rangeSlider1.DrawLabel += RangeSlider1_DrawLabel; |
| 26 | + this.rangeSlider1.ShowLabels = true; |
| 27 | + this.rangeSlider1.Minimum = 1; |
| 28 | + this.rangeSlider1.Maximum = 10; |
| 29 | + this.rangeSlider1.TickFrequency = 1; |
24 | 30 |
|
25 | | -This example sets the slider range from **1 to 10**, with a tick frequency of **1**, and centers the form on the screen. |
| 31 | + // Center the form on the screen |
| 32 | + this.StartPosition = FormStartPosition.CenterScreen; |
| 33 | +} |
| 34 | + |
| 35 | +private void RangeSlider1_DrawLabel(object sender, DrawLabelEventArgs e) |
| 36 | +{ |
| 37 | + // Convert slider value to time intervals |
| 38 | + TimeSpan timeSpan = new TimeSpan(0, 30, 0); |
| 39 | + for (int i = 0; i < e.Value; i++) |
| 40 | + { |
| 41 | + timeSpan = timeSpan.Add(new TimeSpan(0, 30, 0)); |
| 42 | + } |
| 43 | + |
| 44 | + DateTime time = DateTime.Today.Add(timeSpan); |
| 45 | + e.Text = time.ToString("hh:mm tt"); |
| 46 | + e.Handled = true; |
| 47 | +} |
| 48 | +``` |
26 | 49 |
|
27 | | -For more details, refer to the official Syncfusion Knowledge Base article: |
28 | | -🔗 [How to Customize the Range Intervals in WinForms RangeSlider](https://www.syncfusion.com/kb/11982/how-to-customize-the-range-intervals-in-winforms-rangeslider) |
| 50 | +## Reference |
| 51 | +For more details, refer to the official Syncfusion Knowledge Base: https://www.syncfusion.com/kb/11982/how-to-customize-the-range-intervals-in-winforms-rangeslider |
0 commit comments