|
| 1 | +using Modern.Forms; |
| 2 | + |
| 3 | +namespace ControlGallery.Panels |
| 4 | +{ |
| 5 | + /// <summary> |
| 6 | + /// Demonstrates different <see cref="TrackBar"/> configurations in the control gallery. |
| 7 | + /// </summary> |
| 8 | + /// <remarks> |
| 9 | + /// This panel showcases: |
| 10 | + /// <list type="bullet"> |
| 11 | + /// <item><description>A basic horizontal track bar.</description></item> |
| 12 | + /// <item><description>A horizontal track bar with tick marks on both sides.</description></item> |
| 13 | + /// <item><description>A vertical track bar.</description></item> |
| 14 | + /// <item><description>A snapped track bar that rounds values to tick marks.</description></item> |
| 15 | + /// <item><description>A disabled track bar.</description></item> |
| 16 | + /// </list> |
| 17 | + /// </remarks> |
| 18 | + public class TrackBarPanel : Panel |
| 19 | + { |
| 20 | + /// <summary> |
| 21 | + /// Initializes a new instance of the <see cref="TrackBarPanel"/> class. |
| 22 | + /// </summary> |
| 23 | + public TrackBarPanel () |
| 24 | + { |
| 25 | + CreateHorizontalExamples (); |
| 26 | + CreateVerticalExamples (); |
| 27 | + CreateOptionsSection (); |
| 28 | + } |
| 29 | + |
| 30 | + private void CreateHorizontalExamples () |
| 31 | + { |
| 32 | + Controls.Add (new Label { |
| 33 | + Text = "Horizontal", |
| 34 | + Left = 10, |
| 35 | + Top = 10, |
| 36 | + Width = 200, |
| 37 | + Height = 25 |
| 38 | + }); |
| 39 | + |
| 40 | + var horizontal_value_label = Controls.Add (new Label { |
| 41 | + Text = "Value: 25", |
| 42 | + Left = 320, |
| 43 | + Top = 45, |
| 44 | + Width = 120, |
| 45 | + Height = 25 |
| 46 | + }); |
| 47 | + |
| 48 | + var horizontal = Controls.Add (new TrackBar { |
| 49 | + Left = 10, |
| 50 | + Top = 40, |
| 51 | + Width = 280, |
| 52 | + Minimum = 0, |
| 53 | + Maximum = 100, |
| 54 | + Value = 25, |
| 55 | + TickFrequency = 10, |
| 56 | + TickStyle = TickStyle.BottomRight |
| 57 | + }); |
| 58 | + |
| 59 | + horizontal.ValueChanged += (sender, e) => { |
| 60 | + horizontal_value_label.Text = $"Value: {horizontal.Value}"; |
| 61 | + }; |
| 62 | + |
| 63 | + var both_ticks_value_label = Controls.Add (new Label { |
| 64 | + Text = "Value: 60", |
| 65 | + Left = 320, |
| 66 | + Top = 105, |
| 67 | + Width = 120, |
| 68 | + Height = 25 |
| 69 | + }); |
| 70 | + |
| 71 | + var both_ticks = Controls.Add (new TrackBar { |
| 72 | + Left = 10, |
| 73 | + Top = 100, |
| 74 | + Width = 280, |
| 75 | + Minimum = 0, |
| 76 | + Maximum = 100, |
| 77 | + Value = 60, |
| 78 | + TickFrequency = 5, |
| 79 | + TickStyle = TickStyle.Both |
| 80 | + }); |
| 81 | + |
| 82 | + both_ticks.ValueChanged += (sender, e) => { |
| 83 | + both_ticks_value_label.Text = $"Value: {both_ticks.Value}"; |
| 84 | + }; |
| 85 | + |
| 86 | + Controls.Add (new Label { |
| 87 | + Text = "Snap to ticks", |
| 88 | + Left = 10, |
| 89 | + Top = 160, |
| 90 | + Width = 200, |
| 91 | + Height = 25 |
| 92 | + }); |
| 93 | + |
| 94 | + var snap_value_label = Controls.Add (new Label { |
| 95 | + Text = "Value: 30", |
| 96 | + Left = 320, |
| 97 | + Top = 195, |
| 98 | + Width = 120, |
| 99 | + Height = 25 |
| 100 | + }); |
| 101 | + |
| 102 | + var snapped = Controls.Add (new TrackBar { |
| 103 | + Left = 10, |
| 104 | + Top = 190, |
| 105 | + Width = 280, |
| 106 | + Minimum = 0, |
| 107 | + Maximum = 100, |
| 108 | + Value = 30, |
| 109 | + TickFrequency = 10, |
| 110 | + TickStyle = TickStyle.TopLeft, |
| 111 | + SnapToTicks = true |
| 112 | + }); |
| 113 | + |
| 114 | + snapped.ValueChanged += (sender, e) => { |
| 115 | + snap_value_label.Text = $"Value: {snapped.Value}"; |
| 116 | + }; |
| 117 | + |
| 118 | + Controls.Add (new Label { |
| 119 | + Text = "Disabled", |
| 120 | + Left = 10, |
| 121 | + Top = 250, |
| 122 | + Width = 200, |
| 123 | + Height = 25 |
| 124 | + }); |
| 125 | + |
| 126 | + Controls.Add (new TrackBar { |
| 127 | + Left = 10, |
| 128 | + Top = 280, |
| 129 | + Width = 280, |
| 130 | + Minimum = 0, |
| 131 | + Maximum = 100, |
| 132 | + Value = 45, |
| 133 | + TickFrequency = 10, |
| 134 | + TickStyle = TickStyle.BottomRight, |
| 135 | + Enabled = false |
| 136 | + }); |
| 137 | + } |
| 138 | + |
| 139 | + private void CreateVerticalExamples () |
| 140 | + { |
| 141 | + Controls.Add (new Label { |
| 142 | + Text = "Vertical", |
| 143 | + Left = 500, |
| 144 | + Top = 10, |
| 145 | + Width = 100, |
| 146 | + Height = 25 |
| 147 | + }); |
| 148 | + |
| 149 | + var vertical_value_label = Controls.Add (new Label { |
| 150 | + Text = "Value: 75", |
| 151 | + Left = 470, |
| 152 | + Top = 45, |
| 153 | + Width = 120, |
| 154 | + Height = 25 |
| 155 | + }); |
| 156 | + |
| 157 | + var vertical = Controls.Add (new TrackBar { |
| 158 | + Left = 500, |
| 159 | + Top = 80, |
| 160 | + Width = 32, |
| 161 | + Height = 220, |
| 162 | + Orientation = Orientation.Vertical, |
| 163 | + Minimum = 0, |
| 164 | + Maximum = 100, |
| 165 | + Value = 75, |
| 166 | + TickFrequency = 10, |
| 167 | + TickStyle = TickStyle.Both |
| 168 | + }); |
| 169 | + |
| 170 | + vertical.ValueChanged += (sender, e) => { |
| 171 | + vertical_value_label.Text = $"Value: {vertical.Value}"; |
| 172 | + }; |
| 173 | + } |
| 174 | + |
| 175 | + private void CreateOptionsSection () |
| 176 | + { |
| 177 | + Controls.Add (new Label { |
| 178 | + Text = "Interactive example", |
| 179 | + Left = 10, |
| 180 | + Top = 360, |
| 181 | + Width = 200, |
| 182 | + Height = 25 |
| 183 | + }); |
| 184 | + |
| 185 | + var interactive = Controls.Add (new TrackBar { |
| 186 | + Left = 10, |
| 187 | + Top = 390, |
| 188 | + Width = 280, |
| 189 | + Minimum = 0, |
| 190 | + Maximum = 50, |
| 191 | + Value = 10, |
| 192 | + TickFrequency = 5, |
| 193 | + TickStyle = TickStyle.BottomRight |
| 194 | + }); |
| 195 | + |
| 196 | + var value_label = Controls.Add (new Label { |
| 197 | + Text = "Value: 10", |
| 198 | + Left = 320, |
| 199 | + Top = 395, |
| 200 | + Width = 120, |
| 201 | + Height = 25 |
| 202 | + }); |
| 203 | + |
| 204 | + var snap_checkbox = Controls.Add (new CheckBox { |
| 205 | + Text = "Snap to ticks", |
| 206 | + Left = 320, |
| 207 | + Top = 425, |
| 208 | + Width = 150, |
| 209 | + Checked = false |
| 210 | + }); |
| 211 | + |
| 212 | + var tick_style_combo = Controls.Add (new ComboBox { |
| 213 | + Left = 320, |
| 214 | + Top = 455, |
| 215 | + Width = 150 |
| 216 | + }); |
| 217 | + |
| 218 | + tick_style_combo.Items.AddRange (Enum.GetNames<TickStyle> ()); |
| 219 | + tick_style_combo.SelectedItem = TickStyle.BottomRight.ToString (); |
| 220 | + |
| 221 | + interactive.ValueChanged += (sender, e) => { |
| 222 | + value_label.Text = $"Value: {interactive.Value}"; |
| 223 | + }; |
| 224 | + |
| 225 | + snap_checkbox.CheckedChanged += (sender, e) => { |
| 226 | + interactive.SnapToTicks = snap_checkbox.Checked; |
| 227 | + }; |
| 228 | + |
| 229 | + tick_style_combo.SelectedIndexChanged += (sender, e) => { |
| 230 | + if (tick_style_combo.SelectedItem is string selected_text) |
| 231 | + interactive.TickStyle = Enum.Parse<TickStyle> (selected_text); |
| 232 | + }; |
| 233 | + } |
| 234 | + } |
| 235 | +} |
0 commit comments