Skip to content

Commit f8fd991

Browse files
[release/9.0] fix #13305 Baseline SnapLines do not appear in DesignSurface (#13349)
Backport of #13324 to release/9.0 ## The cause of this issue This issue is caused by [PR10279](#10279) These are two of all changes make in [PR10279](#10279) ![image](https://github.com/user-attachments/assets/155740a9-6e1e-4a7c-8581-9d813b1d149b) `BehaviorService`, `DragAssistanceManager` use `SnapLines` to add some effects during design time. `ControlDesigner` has a **_virtual_** property `SnapLines`, but most designers override the property, in other words, _**most designers have customized `SnapLines`**_ ### Code flow before [PR10279](#10279) when `BehaviorService` or `DragAssistanceManager` accesses `SnapLines` , customized `SnapLines` were returned. ### Code flow after [PR10279](#10279) when `BehaviorService` or `DragAssistanceManager` **_accesses `SnapLinesInternal`_** , **_customized `SnapLines` were skipped._** ## Proposed changes - - Use `SnapLines` - <!-- ## Customer Impact - - ## Regression? - Yes / No ## Risk - --> ## Screenshots ### Before ![Image](https://github.com/user-attachments/assets/5650c5d5-8433-4b5e-8723-806867186be2) ### After ![Image](https://github.com/user-attachments/assets/4c528e07-39a9-497b-86d8-3f450f6e634b) ## Test methodology - - manually -
2 parents 7d96dbd + 4e0694c commit f8fd991

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/BehaviorService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ private void TestHook_GetAllSnapLines(ref Message m)
799799

800800
if (host.GetDesigner(comp) is ControlDesigner designer)
801801
{
802-
foreach (SnapLine line in designer.SnapLinesInternal)
802+
foreach (SnapLine line in designer.SnapLines)
803803
{
804804
snapLineInfo.Append($"{line}\tAssociated Control = {designer.Control.Name}:::");
805805
}

src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/Behavior/DragAssistanceManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ internal DragAssistanceManager(
165165
/// </summary>
166166
private void AddSnapLines(ControlDesigner controlDesigner, List<SnapLine> horizontalList, List<SnapLine> verticalList, bool isTarget, bool validTarget)
167167
{
168-
IList<SnapLine> snapLines = controlDesigner.SnapLinesInternal;
168+
IList snapLines = controlDesigner.SnapLines;
169169
// Used for padding snaplines
170170
Rectangle controlRect = controlDesigner.Control.ClientRectangle;
171171
// Used for all others

src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/Behavior/SnapLineTests.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,59 @@ public void SnapLine_ToString(string filter, string expected)
236236

237237
Assert.Equal(expected, snapLine.ToString());
238238
}
239+
240+
// Unit test for https://github.com/dotnet/winforms/issues/13305
241+
[Fact]
242+
public void SnapLine_ReturnOverrided()
243+
{
244+
using ControlDesigner baseDesigner = new();
245+
using Control control = new();
246+
baseDesigner.Initialize(control);
247+
baseDesigner.SnapLines.Count.Should().Be(8);
248+
249+
ControlDesigner derivedDesigner = new ButtonBaseDesigner();
250+
using Button button = new();
251+
derivedDesigner.Initialize(button);
252+
derivedDesigner.SnapLines.Count.Should().Be(9);
253+
254+
derivedDesigner = new ComboBoxDesigner();
255+
using ComboBox comboBox = new();
256+
derivedDesigner.Initialize(comboBox);
257+
derivedDesigner.SnapLines.Count.Should().Be(9);
258+
259+
derivedDesigner = new DateTimePickerDesigner();
260+
using DateTimePicker dateTimePicker = new();
261+
derivedDesigner.Initialize(dateTimePicker);
262+
derivedDesigner.SnapLines.Count.Should().Be(9);
263+
264+
derivedDesigner = new LabelDesigner();
265+
using Label label = new();
266+
derivedDesigner.Initialize(label);
267+
derivedDesigner.SnapLines.Count.Should().Be(9);
268+
269+
derivedDesigner = new ParentControlDesigner();
270+
derivedDesigner.Initialize(control);
271+
derivedDesigner.SnapLines.Count.Should().Be(12);
272+
273+
derivedDesigner = new SplitterPanelDesigner();
274+
using SplitContainer splitContainer = new();
275+
using SplitterPanel splitterPanel = new(splitContainer);
276+
derivedDesigner.Initialize(splitterPanel);
277+
derivedDesigner.SnapLines.Count.Should().Be(4);
278+
279+
derivedDesigner = new TextBoxBaseDesigner();
280+
using TextBox textBox = new();
281+
derivedDesigner.Initialize(textBox);
282+
derivedDesigner.SnapLines.Count.Should().Be(9);
283+
284+
derivedDesigner = new ToolStripContentPanelDesigner();
285+
using ToolStripContentPanel toolStripContentPanel = new();
286+
derivedDesigner.Initialize(toolStripContentPanel);
287+
derivedDesigner.SnapLines.Count.Should().Be(4);
288+
289+
derivedDesigner = new UpDownBaseDesigner();
290+
using DomainUpDown domainUpDown = new();
291+
derivedDesigner.Initialize(domainUpDown);
292+
derivedDesigner.SnapLines.Count.Should().Be(9);
293+
}
239294
}

0 commit comments

Comments
 (0)