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

LinkedLabel.PaintLink doesn't preserve clipping/transform #4857

Closed
RussKie opened this issue Apr 29, 2021 · 3 comments · Fixed by #4901
Closed

LinkedLabel.PaintLink doesn't preserve clipping/transform #4857

RussKie opened this issue Apr 29, 2021 · 3 comments · Fixed by #4901
Assignees
Labels
🪲 bug Product bug (most likely)

Comments

@RussKie
Copy link
Member

RussKie commented Apr 29, 2021

Problem description:

While testing a fix #4860, and invoking a designer actions for a Panel control got a failure while rendering a LinkLabel:
image

image

>	System.Windows.Forms.dll!System.Windows.Forms.TextRenderer.GetApplyStateFlags(System.Drawing.IDeviceContext deviceContext = {System.Drawing.Graphics}, System.Windows.Forms.TextFormatFlags textFormatFlags = VerticalCenter | NoPrefix) Line 623	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.TextRenderer.DrawTextInternal(System.Drawing.IDeviceContext dc = {System.Drawing.Graphics}, System.ReadOnlySpan<char> text = "Dock in Parent Container", System.Drawing.Font font = {Name = "Segoe UI" Size=9}, System.Drawing.Rectangle bounds = {X = 0 Y = 0 Width = 139 Height = 15}, System.Drawing.Color foreColor = "{Name=HotTrack, ARGB=(255, 0, 102, 204)}", System.Drawing.Color backColor = "{Name=0, ARGB=(0, 0, 0, 0)}", System.Windows.Forms.TextFormatFlags flags = VerticalCenter | NoPrefix) Line 304	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.TextRenderer.DrawText(System.Drawing.IDeviceContext dc = {System.Drawing.Graphics}, string text = "Dock in Parent Container", System.Drawing.Font font = {Name = "Segoe UI" Size=9}, System.Drawing.Rectangle bounds = {X = 0 Y = 0 Width = 139 Height = 15}, System.Drawing.Color foreColor = "{Name=HotTrack, ARGB=(255, 0, 102, 204)}", System.Windows.Forms.TextFormatFlags flags = VerticalCenter | NoPrefix) Line 201	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.LinkLabel.PaintLink(System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {X = 0 Y = 0 Width = 139 Height = 15}}, System.Windows.Forms.LinkLabel.Link link = {System.Windows.Forms.LinkLabel.Link}, System.Drawing.SolidBrush foreBrush = {Color = "{Name=ControlText, ARGB=(255, 0, 0, 0)}"}, System.Drawing.SolidBrush linkBrush = {Color = "{Name=HotTrack, ARGB=(255, 0, 102, 204)}"}, bool optimizeBackgroundRendering = false, System.Drawing.RectangleF finalrect = {X = 0 Y = 0 Width = 139 Height = 15}) Line 1503	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.LinkLabel.OnPaint(System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {X = 0 Y = 0 Width = 139 Height = 15}}) Line 1274	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs e = {ClipRectangle = {X = 0 Y = 0 Width = 139 Height = 15}}, short layer = 2) Line 8717	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 12480	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 12881	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Label.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 1516	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.LinkLabel.WndProc(ref System.Windows.Forms.Message msg = {System.Windows.Forms.Message}) Line 2035	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 67	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 121	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd = 0x00000000007100f8, Interop.User32.WM msg = PAINT, System.IntPtr wparam = 0x0000000000000000, System.IntPtr lparam = 0x0000000000000000) Line 373	C#	Symbols loaded.
 	[Native to Managed Transition]		Annotated Frame
 	[Managed to Native Transition]		Annotated Frame
 	System.Windows.Forms.Primitives.dll!Interop.User32.UpdateWindow(IHandle hWnd = {System.ComponentModel.Design.DesignerActionToolStripDropDown}) Line 18	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.Update() Line 11304	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.ClearAllSelectionsExcept(System.Windows.Forms.ToolStripItem item = null) Line 2000	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.ClearAllSelections() Line 1950	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.OnLostFocus(System.EventArgs e = {System.EventArgs}) Line 3602	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeLostFocus(System.Windows.Forms.Control toInvoke = {System.ComponentModel.Design.DesignerActionToolStripDropDown}, System.EventArgs e = {System.EventArgs}) Line 8151	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WmKillFocus(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 12039	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 13014	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 1505	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 4975	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripDropDown.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 2134	C#	Symbols loaded.
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignerActionToolStripDropDown.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 1112	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 67	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 121	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd = 0x00000000002902fe, Interop.User32.WM msg = KILLFOCUS, System.IntPtr wparam = 0x000000000117130c, System.IntPtr lparam = 0x0000000000000000) Line 373	C#	Symbols loaded.
 	[Native to Managed Transition]		Annotated Frame
 	[Managed to Native Transition]		Annotated Frame
 	System.Windows.Forms.Primitives.dll!Interop.User32.SetFocus(System.Runtime.InteropServices.HandleRef hWnd = {System.Runtime.InteropServices.HandleRef}) Line 17	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.FocusInternal() Line 5542	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.Focus() Line 5529	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripControlHost.Focus() Line 478	C#	Symbols loaded.
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignerActionToolStripDropDown.CheckFocusIsRight() Line 835	C#	Symbols loaded.
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignerActionUI.OnShowComplete(object sender = {System.ComponentModel.Design.DesignerActionToolStripDropDown}, System.EventArgs e = {System.EventArgs}) Line 769	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry tme = {System.Windows.Forms.Control.ThreadMethodEntry}) Line 6475	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj = {System.Windows.Forms.Control.ThreadMethodEntry}) Line 6455	C#	Symbols loaded.
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown	No symbols loaded.
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown	No symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallback(System.Windows.Forms.Control.ThreadMethodEntry tme = {System.Windows.Forms.Control.ThreadMethodEntry}) Line 6432	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbacks() Line 6530	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 13159	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 1505	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStrip.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 4975	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ToolStripDropDown.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 2134	C#	Symbols loaded.
 	System.Windows.Forms.Design.dll!System.ComponentModel.Design.DesignerActionToolStripDropDown.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 1112	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 67	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 121	C#	Symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd = 0x00000000002902fe, Interop.User32.WM msg = 49793, System.IntPtr wparam = 0x0000000000000000, System.IntPtr lparam = 0x0000000000000000) Line 373	C#	Symbols loaded.

This issue appears to be similar to #4610, with the root cause introduced in #4525.

Expected behavior:

image

With this change it appears to work:

diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/LinkLabel.cs b/src/System.Windows.Forms/src/System/Windows/Forms/LinkLabel.cs
index 123873bc7..f30edc3b5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/LinkLabel.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/LinkLabel.cs
@@ -1506,7 +1506,7 @@ namespace System.Windows.Forms
                             font,
                             clientRectWithPadding,
                             brushColor,
-                            CreateTextFormatFlags(clientRectWithPadding.Size));
+                            CreateTextFormatFlags(clientRectWithPadding.Size) | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.PreserveGraphicsTranslateTransform);
                     }
 
                     if (Focused && ShowFocusCues && FocusLink == link)
@RussKie RussKie added 🪲 bug Product bug (most likely) 💥 regression-preview Regression from a preview release labels Apr 29, 2021
@RussKie RussKie added this to the 6.0 Preview5 milestone Apr 30, 2021
@RussKie RussKie added the Priority:1 Work that is critical for the release, but we could probably ship without label Apr 30, 2021
@JeremyKuhne
Copy link
Member

@RussKie can you please provide a repro for this. Looking at the old code it appears that it would not apply transforms either but I can't fully validate without knowing exactly how to reproduce your specific observed problem.

@RussKie
Copy link
Member Author

RussKie commented May 5, 2021

You can grab the sample from #4860.
From my tests it trips on the assert in DEBUG mode only. A RELEASE build works just fine...

@RussKie RussKie removed Priority:1 Work that is critical for the release, but we could probably ship without 💥 regression-preview Regression from a preview release labels May 12, 2021
RussKie added a commit to RussKie/winforms that referenced this issue May 13, 2021
While painting LinkedLabel we modify device context before drawing the
label's text. Because of that we hit the asserts in TextRenderer.GetApplyStateFlags.
Since the DC state is expected, skip the assertions.

Closes dotnet#4857
@ghost ghost added the 🚧 work in progress Work that is current in progress label May 13, 2021
RussKie added a commit that referenced this issue May 13, 2021
While painting LinkedLabel we modify device context before drawing the
label's text. Because of that we hit the asserts in TextRenderer.GetApplyStateFlags.
Since the DC state is expected, skip the assertions.

Closes #4857
@ghost ghost removed the 🚧 work in progress Work that is current in progress label May 13, 2021
@RussKie RussKie removed this from the 6.0 Preview5 milestone May 13, 2021
@Marie-Shi
Copy link

Verified this issue with 6.0.100-preview.5.21276.14 from Release/6.0.1XX-preview5 branch of https://github.com/dotnet/installer, it is fixed.
update2

@ghost ghost locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🪲 bug Product bug (most likely)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants