Skip to content

Commit 0fee68a

Browse files
Leaf ShiLeaf Shi
authored andcommitted
Invoking UpdateOwnerDraw in BackgroundImage property to update the OwnerDraw flag to ensure correct visual behavior
1 parent d495460 commit 0fee68a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/System.Windows.Forms/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
override System.Windows.Forms.Button.BackgroundImage.set -> void
12
static System.Windows.Forms.Application.SetColorMode(System.Windows.Forms.SystemColorMode systemColorMode) -> void
23
static System.Windows.Forms.TaskDialog.ShowDialogAsync(nint hwndOwner, System.Windows.Forms.TaskDialogPage! page, System.Windows.Forms.TaskDialogStartupLocation startupLocation = System.Windows.Forms.TaskDialogStartupLocation.CenterOwner) -> System.Threading.Tasks.Task<System.Windows.Forms.TaskDialogButton!>!
34
static System.Windows.Forms.TaskDialog.ShowDialogAsync(System.Windows.Forms.IWin32Window! owner, System.Windows.Forms.TaskDialogPage! page, System.Windows.Forms.TaskDialogStartupLocation startupLocation = System.Windows.Forms.TaskDialogStartupLocation.CenterOwner) -> System.Threading.Tasks.Task<System.Windows.Forms.TaskDialogButton!>!

src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/Button.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ public virtual DialogResult DialogResult
148148
}
149149
}
150150

151+
public override Image? BackgroundImage
152+
{
153+
set
154+
{
155+
base.BackgroundImage = value;
156+
157+
// BackgroundImage changes may affect rendering logic,
158+
// so we manually update the OwnerDraw flag to ensure correct visual behavior.
159+
UpdateOwnerDraw();
160+
}
161+
}
162+
151163
/// <summary>
152164
/// Defines, whether the control is owner-drawn. Based on this,
153165
/// the UserPaint flags get set, which in turn makes it later
@@ -166,8 +178,6 @@ private protected override bool OwnerDraw
166178
&& Image is null
167179
// ...or a BackgroundImage, except if...
168180
&& BackgroundImage is null
169-
// Delay BackgroundImage check until handle is created to avoid early null misjudgment
170-
&& IsHandleCreated
171181
// ...the user wants to opt out of implicit DarkMode rendering.
172182
&& DarkModeRequestState is true
173183

0 commit comments

Comments
 (0)