Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port TrackBarDesigner to runtime #9703

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/System.Design/src/System.Design.Forwards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ToolStripItemDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ToolStripMenuItemDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TreeViewDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.TrackBarDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.UpDownBaseDesigner))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.UserControlDocumentDesigner))]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;

namespace System.Windows.Forms.Design;

internal class TrackBarDesigner : ControlDesigner
{
public TrackBarDesigner()
{
AutoResizeHandles = true;
}

public override SelectionRules SelectionRules
{
get
{
SelectionRules rules = base.SelectionRules;
rules |= SelectionRules.AllSizeable;

if (GetPropertyValue<bool>(Component, nameof(TrackBar.AutoSize)))
{
var orientation = GetPropertyValue<Orientation?>(Component, nameof(TrackBar.Orientation));
if (orientation != null)
LeafShi1 marked this conversation as resolved.
Show resolved Hide resolved
{
orientation = Orientation.Horizontal;
}

switch (orientation)
{
case Orientation.Horizontal:
rules &= ~(SelectionRules.TopSizeable | SelectionRules.BottomSizeable);
break;
case Orientation.Vertical:
rules &= ~(SelectionRules.LeftSizeable | SelectionRules.RightSizeable);
break;
}
}

return rules;
}
}

private static T? GetPropertyValue<T>(object component, string propertyName)
{
PropertyDescriptor? prop = TypeDescriptor.GetProperties(component)[propertyName];
return prop is null ? default : (T?)prop.GetValue(component);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ private void CreateDesignSurface(int n)
layoutPanel.Controls.Add(subButton1OfLayoutPanel);
layoutPanel.Controls.Add(subButton2OfLayoutPanel);

TrackBar trackBar = surface.CreateControl<TrackBar>(new Size(200, 50), new Point(250, 220));

FolderBrowserDialog folderBrowserDialog = surface.CreateComponent<FolderBrowserDialog>();
SaveFileDialog saveFileDialog = surface.CreateComponent<SaveFileDialog>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class DesignerAttributeTests
"System.Windows.Forms.Design.ToolStripContainerDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"System.Windows.Forms.Design.ToolStripContentPanelDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"System.Windows.Forms.Design.ToolStripPanelDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"System.Windows.Forms.Design.TrackBarDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
"System.Windows.Forms.Design.WebBrowserDesigner, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",

// https://github.com/dotnet/winforms/issues/1115
Expand Down
Loading