Open KlausLoeffelmann opened 1 year ago
can you test, if this is a Framework regression? Thanks!
@Olina-Zhang
It isn't a regression issue, .Net framwork and .Net 8.0 have the same behavior. When setting Form's BackColor with dark value and ForeColor with light value, the added GroupBox has same value of BackColor and ForeColor, but the text is dark. We need to set ForeColor with same value again, it works well.
Thanks for testing that, appreciated!!
It doesn't work in certain situations, though, where the Designer notices an ambient condition already, and the Serializer doesn't spill out code for that, because at that point it "knows" that the Property is the same as the assigned parent, and so doesn't see the need to serialize it because the ShouldSerializeForeColor
in that setup returns false
. And then it's impossible to set.
This is one of the rare cases, btw, where the order in which the Designer decides to serialize does have an effect on the outcome (@dreddy-work FYI), which we all don't like 😸!
This is really bad for Dark Mode scenarios, and we would need to fix this rather sooner than later!
This issue is now marked as "help wanted", and we’re looking for a community volunteer to work on this issue. If we receive no interest in 180 days, we will close the issue (or poor Klaus needs to fix it 😸). To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
@elachlan, OT: Could you send me an email at klaus ';dot' loeffelmann 'at;' microsoft '.' com so I could follow-up with you on an issue? Thanks! (And thanks for correcting the @ to Olina here!!)
@KlausLoeffelmann email is sent.
@KlausLoeffelmann
Why not set it up manually?
namespace TestGroupBox
{
public class MyGroupBox : GroupBox
{
public MyGroupBox()
{
//We need to set it here
ForeColor = base.ForeColor; // SystemColors.ControlText;
}
protected override void OnParentChanged(EventArgs e)
{
base.OnParentChanged(e);
// if ForeColor need to be changed if the Parent ForeColor changed
Form parentfrm = this.FindForm();
if (parentfrm != null && this.ForeColor == SystemColors.ControlText)
parentfrm.ForeColorChanged += delegate { ForeColor = parentfrm.ForeColor;};
}
protected override void OnPaint(PaintEventArgs e)
{
if (this.FindForm() != null && this.ForeColor == SystemColors.ControlText)
ForeColor = this.FindForm().ForeColor;
base.OnPaint(e);
}
}
}
I made quick design time debug session and it work fine
https://github.com/dotnet/winforms/assets/12494184/1da159d9-f5cb-4157-8d72-899651b7503c
I am not sure what you mean. This property/properties being ambient, should not make any additional effort to pick colors up necessary. That's why I consider this to be a bug, and we should fix it.
.NET version
All. Unfortunately.
Did it work in .NET Framework?
No. Unfortunately.
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No.
Issue description
When the GroupBox is inheriting its ForeColor by its Parent control, the color is not correctly applied.
Steps to reproduce
The GroupBox should render the Text in light on dark background, but only the Frame is light. The text gets rendered in the original color:
@Olina, can you test, if this is a Framework regression? Thanks!