Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions samples/ControlGallery/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public MainForm ()
tree.Items.Add ("TextBox", ImageLoader.Get ("button.png"));
tree.Items.Add ("TitleBar", ImageLoader.Get ("button.png"));
tree.Items.Add ("ToolBar", ImageLoader.Get ("button.png"));
tree.Items.Add ("TrackBar", ImageLoader.Get ("button.png"));
tree.Items.Add ("TreeView", ImageLoader.Get ("button.png"));

tree.ItemSelected += Tree_ItemSelected;
Expand Down Expand Up @@ -140,6 +141,8 @@ private void Tree_ItemSelected (object? sender, EventArgs<TreeViewItem> e)
return new TitleBarPanel ();
case "ToolBar":
return new ToolBarPanel ();
case "TrackBar":
return new TrackBarPanel ();
case "TreeView":
return new TreeViewPanel ();
}
Expand Down
235 changes: 235 additions & 0 deletions samples/ControlGallery/Panels/TrackBarPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
using Modern.Forms;

namespace ControlGallery.Panels
{
/// <summary>
/// Demonstrates different <see cref="TrackBar"/> configurations in the control gallery.
/// </summary>
/// <remarks>
/// This panel showcases:
/// <list type="bullet">
/// <item><description>A basic horizontal track bar.</description></item>
/// <item><description>A horizontal track bar with tick marks on both sides.</description></item>
/// <item><description>A vertical track bar.</description></item>
/// <item><description>A snapped track bar that rounds values to tick marks.</description></item>
/// <item><description>A disabled track bar.</description></item>
/// </list>
/// </remarks>
public class TrackBarPanel : Panel
{
/// <summary>
/// Initializes a new instance of the <see cref="TrackBarPanel"/> class.
/// </summary>
public TrackBarPanel ()
{
CreateHorizontalExamples ();
CreateVerticalExamples ();
CreateOptionsSection ();
}

private void CreateHorizontalExamples ()
{
Controls.Add (new Label {
Text = "Horizontal",
Left = 10,
Top = 10,
Width = 200,
Height = 25
});

var horizontal_value_label = Controls.Add (new Label {
Text = "Value: 25",
Left = 320,
Top = 45,
Width = 120,
Height = 25
});

var horizontal = Controls.Add (new TrackBar {
Left = 10,
Top = 40,
Width = 280,
Minimum = 0,
Maximum = 100,
Value = 25,
TickFrequency = 10,
TickStyle = TickStyle.BottomRight
});

horizontal.ValueChanged += (sender, e) => {
horizontal_value_label.Text = $"Value: {horizontal.Value}";
};

var both_ticks_value_label = Controls.Add (new Label {
Text = "Value: 60",
Left = 320,
Top = 105,
Width = 120,
Height = 25
});

var both_ticks = Controls.Add (new TrackBar {
Left = 10,
Top = 100,
Width = 280,
Minimum = 0,
Maximum = 100,
Value = 60,
TickFrequency = 5,
TickStyle = TickStyle.Both
});

both_ticks.ValueChanged += (sender, e) => {
both_ticks_value_label.Text = $"Value: {both_ticks.Value}";
};

Controls.Add (new Label {
Text = "Snap to ticks",
Left = 10,
Top = 160,
Width = 200,
Height = 25
});

var snap_value_label = Controls.Add (new Label {
Text = "Value: 30",
Left = 320,
Top = 195,
Width = 120,
Height = 25
});

var snapped = Controls.Add (new TrackBar {
Left = 10,
Top = 190,
Width = 280,
Minimum = 0,
Maximum = 100,
Value = 30,
TickFrequency = 10,
TickStyle = TickStyle.TopLeft,
SnapToTicks = true
});

snapped.ValueChanged += (sender, e) => {
snap_value_label.Text = $"Value: {snapped.Value}";
};

Controls.Add (new Label {
Text = "Disabled",
Left = 10,
Top = 250,
Width = 200,
Height = 25
});

Controls.Add (new TrackBar {
Left = 10,
Top = 280,
Width = 280,
Minimum = 0,
Maximum = 100,
Value = 45,
TickFrequency = 10,
TickStyle = TickStyle.BottomRight,
Enabled = false
});
}

private void CreateVerticalExamples ()
{
Controls.Add (new Label {
Text = "Vertical",
Left = 500,
Top = 10,
Width = 100,
Height = 25
});

var vertical_value_label = Controls.Add (new Label {
Text = "Value: 75",
Left = 470,
Top = 45,
Width = 120,
Height = 25
});

var vertical = Controls.Add (new TrackBar {
Left = 500,
Top = 80,
Width = 32,
Height = 220,
Orientation = Orientation.Vertical,
Minimum = 0,
Maximum = 100,
Value = 75,
TickFrequency = 10,
TickStyle = TickStyle.Both
});

vertical.ValueChanged += (sender, e) => {
vertical_value_label.Text = $"Value: {vertical.Value}";
};
}

private void CreateOptionsSection ()
{
Controls.Add (new Label {
Text = "Interactive example",
Left = 10,
Top = 360,
Width = 200,
Height = 25
});

var interactive = Controls.Add (new TrackBar {
Left = 10,
Top = 390,
Width = 280,
Minimum = 0,
Maximum = 50,
Value = 10,
TickFrequency = 5,
TickStyle = TickStyle.BottomRight
});

var value_label = Controls.Add (new Label {
Text = "Value: 10",
Left = 320,
Top = 395,
Width = 120,
Height = 25
});

var snap_checkbox = Controls.Add (new CheckBox {
Text = "Snap to ticks",
Left = 320,
Top = 425,
Width = 150,
Checked = false
});

var tick_style_combo = Controls.Add (new ComboBox {
Left = 320,
Top = 455,
Width = 150
});

tick_style_combo.Items.AddRange (Enum.GetNames<TickStyle> ());
tick_style_combo.SelectedItem = TickStyle.BottomRight.ToString ();

interactive.ValueChanged += (sender, e) => {
value_label.Text = $"Value: {interactive.Value}";
};

snap_checkbox.CheckedChanged += (sender, e) => {
interactive.SnapToTicks = snap_checkbox.Checked;
};

tick_style_combo.SelectedIndexChanged += (sender, e) => {
if (tick_style_combo.SelectedItem is string selected_text)
interactive.TickStyle = Enum.Parse<TickStyle> (selected_text);
};
}
}
}
1 change: 1 addition & 0 deletions src/Modern.Forms/Renderers/RenderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static RenderManager ()
SetRenderer<TabStrip> (new TabStripRenderer ());
SetRenderer<TextBox> (new TextBoxRenderer ());
SetRenderer<ToolBar> (new ToolBarRenderer ());
SetRenderer<TrackBar> (new TrackBarRenderer ());
SetRenderer<TreeView> (new TreeViewRenderer ());
}

Expand Down
Loading
Loading