|
1 | 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 | | - |
4 | | -## Why Customize the Range? |
5 | | -Customizing the range intervals allows you to: |
6 | | -- Define the minimum and maximum values for the slider. |
7 | | -- Control the tick frequency for precise value selection. |
8 | | -- Display custom labels (e.g., time intervals) for better user experience. |
9 | | - |
10 | | -## Key Properties |
11 | | - |
12 | | -- **Minimum**: Sets the lowest value of the slider. |
13 | | -- **Maximum**: Defines the highest value of the slider. |
14 | | -- **TickFrequency**: Determines the interval between ticks. |
15 | | -- **ShowLabels**: Enables label display on the slider. |
16 | | -- **StartPosition**: Specifies the initial position of the form. |
17 | | - |
18 | | -## Example Code |
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; |
30 | | - |
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 | | -``` |
49 | | - |
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 |
52 | | - |
53 | | -## Output |
54 | | - |
| 2 | +This sample demonstrates how to build a user-friendly time-scale slider in a WinForms application using the Syncfusion RangeSlider. It shows how to customize tick intervals, format labels (e.g., 12-hour time), and configure minimum/maximum values so users can scrub through a logical range like half-hour increments across a day. |
| 3 | + |
| 4 | +## Features |
| 5 | +- Set minimum/maximum slider bounds for the domain |
| 6 | +- Configure tick frequency for uniform intervals (e.g., every 30 minutes) |
| 7 | +- Show labels along the track for better readability |
| 8 | +- Customize label text via DrawLabel to display formatted values (e.g., 01:00 PM) |
| 9 | +- Optional snapping behavior through TickFrequency |
| 10 | +- Easy to center and initialize with form StartPosition |
| 11 | + |
| 12 | +## Getting Started |
| 13 | +1. Create a new Windows Forms App (.NET Framework or .NET) in Visual Studio. |
| 14 | +2. Install the NuGet package: Syncfusion.Tools.Windows. |
| 15 | +3. Add a RangeSlider (namespace: Syncfusion.Windows.Forms.Tools) to your form (e.g., rangeSlider1). |
| 16 | +4. Configure core properties and hook the DrawLabel event to customize the label text. |
| 17 | + |
| 18 | +## Usage Tips |
| 19 | +- Map numeric ticks to domain values (minutes, distance, progress) inside DrawLabel. |
| 20 | +- Adjust Minimum/Maximum to match your domain length. For a 24-hour range at 30-minute intervals, you would use 0..48 with TickFrequency = 1. |
| 21 | +- Use ShowLabels for readability; hide if labels are too dense and render a legend elsewhere. |
| 22 | +- If you need a specific start time, offset your base DateTime accordingly in DrawLabel. |
| 23 | + |
| 24 | +## About the Sample |
| 25 | +This sample provides a concise starting point for building domain-aware sliders in WinForms. It demonstrates mapping numeric ticks to real-world values (e.g., half-hour time slots), customizing label rendering for human-friendly formats, and setting uniform tick intervals for predictable navigation. Extend it by changing the domain (dates, percentages, distances), providing snapping and selection logic, and applying your app theme. The goal is to help users scrub, read, and select values effortlessly with clear, formatted labels. |
0 commit comments