-
Notifications
You must be signed in to change notification settings - Fork 998
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
The default value is not displayed in the correct position after setting SelectedObject property for PropertyGird control #4593
Comments
This is a regression surfaced by #4525. Before #4525 any modifications to a winforms/src/System.Windows.Forms.Primitives/src/System/Windows/Forms/DeviceContextHdcScope.cs Lines 52 to 55 in 7b6d433
Since #4525 we rely on flags passed into DrawTextInternal completely side-stepping any modifications applied to a Graphics object. PropertyGrid performs clipping and transformations when rendering values:winforms/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/PropertyGridView.cs Lines 1395 to 1438 in 7b6d433
It looks like an oversight (or a sad omission during the winforms/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/GridEntry.cs Lines 2365 to 2366 in 7b6d433
winforms/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/GridEntry.cs Lines 2385 to 2392 in 7b6d433
...whilst the label rendering code does: winforms/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/GridEntry.cs Line 2085 in 7b6d433
winforms/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGrid.cs Lines 5322 to 5326 in 7b6d433
This looks a fix: diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/GridEntry.cs b/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/GridEntry.cs
index 75b07f49c..41f095bd6 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/GridEntry.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/PropertyGridInternal/GridEntry.cs
@@ -2389,7 +2389,7 @@ namespace System.Windows.Forms.PropertyGridInternal
textRectangle,
textColor,
backColor,
- (TextFormatFlags)format);
+ (TextFormatFlags)format | PropertyGrid.MeasureTextHelper.GetTextRendererFlags());
ValueToolTipLocation = doToolTip ? new Point(rect.X + 2, rect.Y - 1) : InvalidPoint;
}
May also worth adding this as a guard: diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/TextRenderer.cs b/src/System.Windows.Forms/src/System/Windows/Forms/TextRenderer.cs
index d05a1e8f5..05272586f 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/TextRenderer.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/TextRenderer.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics;
using System.Drawing;
using System.Drawing.Text;
using static Interop;
@@ -603,7 +604,7 @@ namespace System.Windows.Forms
/// </summary>
private static ApplyGraphicsProperties GetApplyStateFlags(IDeviceContext deviceContext, TextFormatFlags textFormatFlags)
{
- if (deviceContext is not Graphics)
+ if (deviceContext is not Graphics graphics)
{
return ApplyGraphicsProperties.None;
}
@@ -619,6 +620,16 @@ namespace System.Windows.Forms
apply |= ApplyGraphicsProperties.TranslateTransform;
}
+ Debug.Assert(apply.HasFlag(ApplyGraphicsProperties.Clipping)
+ || graphics.Clip is null
+ || graphics.Clip.GetHrgn(graphics) == IntPtr.Zero,
+ "Must preserve Graphics clipping region!");
+
+ Debug.Assert(apply.HasFlag(ApplyGraphicsProperties.TranslateTransform)
+ || graphics.Transform is null
+ || graphics.Transform.IsIdentity,
+ "Must preserve Graphics transformation!");
+
return apply;
}
} |
Your fix looks right, and I like the assert. |
Agreed - we should get this in 5.0.5 for sure. |
Am I understand right, that this regression will be introduced in 5.0.4 anyway? |
5.0.4 has been snapped few weeks ago, and is about to be released. Unfortunately it is too late in the cycle to undo or fix it in this release.
Sadly we messed it up, sorry.
|
Thanks for the info (forewarned is forearmed). We need to stick with 5.0.3 then... |
This issue will noted in the release notes, I just hadn't have a chance to add it yet.
|
I've updated the known issues docs, these will be published when 5.0.4 and 6.0p2 are released |
The fix introduced in dotnet#4525 has redirected the `PropertyGrid` value rendering through a different code path which only relies on flags passed into `DrawTextInternal` completely side-stepping any modifications applied to the `Graphics` object. However the `PropertyGrid` value rendering routines do modify the `Graphics` object (applying clipping and transformations) but do not pass the necessary flags to `DrawTextInternal`. Fix by applying the necessary flags to preserve the `Graphics` modifications, and add debug-time asserts to check that necessary flags are applies, if the underlying `Graphics` object is modified. Fixes dotnet#4593
The fix introduced in #4525 has redirected the `PropertyGrid` value rendering through a different code path which only relies on flags passed into `DrawTextInternal` completely side-stepping any modifications applied to the `Graphics` object. However the `PropertyGrid` value rendering routines do modify the `Graphics` object (applying clipping and transformations) but do not pass the necessary flags to `DrawTextInternal`. Fix by applying the necessary flags to preserve the `Graphics` modifications, and add debug-time asserts to check that necessary flags are applies, if the underlying `Graphics` object is modified. Fixes #4593
The fix introduced in dotnet#4525 has redirected the `PropertyGrid` value rendering through a different code path which only relies on flags passed into `DrawTextInternal` completely side-stepping any modifications applied to the `Graphics` object. However the `PropertyGrid` value rendering routines do modify the `Graphics` object (applying clipping and transformations) but do not pass the necessary flags to `DrawTextInternal`. Fix by applying the necessary flags to preserve the `Graphics` modifications, and add debug-time asserts to check that necessary flags are applies, if the underlying `Graphics` object is modified. Fixes dotnet#4593 (cherry picked from commit 34cdcf6)
The changelog is updated to reflect the state of the current release. |
Forgot to post link of the doc - sorry :( I meant this: https://github.com/dotnet/core/blob/main/release-notes/5.0/5.0-known-issues.md |
The fix introduced in #4525 has redirected the `PropertyGrid` value rendering through a different code path which only relies on flags passed into `DrawTextInternal` completely side-stepping any modifications applied to the `Graphics` object. However the `PropertyGrid` value rendering routines do modify the `Graphics` object (applying clipping and transformations) but do not pass the necessary flags to `DrawTextInternal`. Fix by applying the necessary flags to preserve the `Graphics` modifications, and add debug-time asserts to check that necessary flags are applies, if the underlying `Graphics` object is modified. Fixes #4593 (cherry picked from commit 34cdcf6)
@RussKie Any advice how to specify exact runtime version with framework-dependent applications?
Initially, I didn't read the documentation carefully and was sure that the OMG I didn't realize the magnitude of the whole problem - 5.0.3 will be overwritten with 5.0.4 by WU anyway. We have big big troubles now... 😭 Am I understand right, that on machines where 5.0.4 will be installed the only options are:
? |
I'm afraid I don't know enough about the .NET deployments via the WU. Manually it is possible to install the runtimes side-by-side. You can define how you wish the runtime to be resolved, please check https://github.com/dotnet/runtime/blob/main/docs/design/features/framework-version-resolution.md |
.NET Core Version: .Net SDK 6.0.100-preview.2.21120.3, .Net SDK 5.0.104 from March 2021 Update Test Pass
Have you experienced this same bug with .NET Framework?:
No
Problem description:
The default value is not displayed in the correct position after setting SelectedObject property for PropertyGird control. It seems to be displayed in the upper left corner of the propertygrid.
Expected behavior:
After setting the SelectedObject property for the PropertyGird control, it should display correct default values.
More Info:
This is a regression issue, it cannot reproduce on .Net SDK 5.0.103 and .Net SDK 6.0.100-preview.2.21111.1, but can reproduce on .Net SDK 5.0.104 from March 2021 Update Test Pass and .Net SDK 6.0.100-preview.2.21112.1.
Minimal repro:
Or
Extract the attached project and open it.
Test.zip
Build and run this application, observe the PropertyGrid.
The text was updated successfully, but these errors were encountered: