Skip to content

Commit cf32e9c

Browse files
Fix some CTI found issues around the new form border attributes APIs.
1 parent bace995 commit cf32e9c

File tree

1 file changed

+19
-63
lines changed
  • src/System.Windows.Forms/src/System/Windows/Forms

1 file changed

+19
-63
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/Form.cs

Lines changed: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ public partial class Form : ContainerControl
136136

137137
private static readonly int s_propOpacity = PropertyStore.CreateKey();
138138
private static readonly int s_propTransparencyKey = PropertyStore.CreateKey();
139-
private static readonly int s_propFormBorderColor = PropertyStore.CreateKey();
140-
private static readonly int s_propFormCaptionBackColor = PropertyStore.CreateKey();
141-
142-
private static readonly int s_propFormCaptionTextColor = PropertyStore.CreateKey();
143139
private static readonly int s_propFormCornerPreference = PropertyStore.CreateKey();
144140

145141
// Form per instance members
@@ -2364,6 +2360,15 @@ public FormCornerPreference FormCornerPreference
23642360
return;
23652361
}
23662362

2363+
_ = value switch
2364+
{
2365+
FormCornerPreference.Default => value,
2366+
FormCornerPreference.DoNotRound => value,
2367+
FormCornerPreference.Round => value,
2368+
FormCornerPreference.RoundSmall => value,
2369+
_ => throw new ArgumentOutOfRangeException(nameof(value))
2370+
};
2371+
23672372
if (value == FormCornerPreference.Default)
23682373
{
23692374
Properties.RemoveObject(s_propFormCornerPreference);
@@ -2425,37 +2430,20 @@ private unsafe void SetFormCornerPreferenceInternal(FormCornerPreference cornerP
24252430
[Experimental(DiagnosticIDs.ExperimentalDarkMode, UrlFormat = Application.WinFormsExperimentalUrl)]
24262431
public Color FormBorderColor
24272432
{
2428-
get
2429-
{
2430-
if (Properties.ContainsObject(s_propFormBorderColor))
2431-
{
2432-
return Properties.GetColor(s_propFormBorderColor);
2433-
}
2434-
else
2435-
{
2436-
if (!IsHandleCreated || IsAncestorSiteInDesignMode)
2437-
{
2438-
return Color.Empty;
2439-
}
2433+
get => GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR);
24402434

2441-
return GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR);
2442-
}
2443-
}
24442435
set
24452436
{
24462437
if (value == FormBorderColor)
24472438
{
24482439
return;
24492440
}
24502441

2451-
if (!IsHandleCreated)
2442+
if (IsHandleCreated)
24522443
{
2453-
Properties.SetColor(s_propFormBorderColor, value);
2454-
return;
2444+
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR, value);
24552445
}
24562446

2457-
Properties.SetColor(s_propFormBorderColor, value);
2458-
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_BORDER_COLOR, value);
24592447
OnFormBorderColorChanged(EventArgs.Empty);
24602448
}
24612449
}
@@ -2482,35 +2470,19 @@ protected virtual void OnFormBorderColorChanged(EventArgs e)
24822470
[Experimental(DiagnosticIDs.ExperimentalDarkMode, UrlFormat = Application.WinFormsExperimentalUrl)]
24832471
public Color FormCaptionBackColor
24842472
{
2485-
get
2486-
{
2487-
if (Properties.ContainsObject(s_propFormCaptionBackColor))
2488-
{
2489-
return Properties.GetColor(s_propFormCaptionBackColor);
2490-
}
2491-
2492-
if (!IsHandleCreated || IsAncestorSiteInDesignMode)
2493-
{
2494-
return Color.Empty;
2495-
}
2496-
2497-
return GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR);
2498-
}
2473+
get => GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR);
24992474
set
25002475
{
25012476
if (value == FormCaptionBackColor)
25022477
{
25032478
return;
25042479
}
25052480

2506-
if (!IsHandleCreated)
2481+
if (IsHandleCreated)
25072482
{
2508-
Properties.SetColor(s_propFormCaptionBackColor, value);
2509-
return;
2483+
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR, value);
25102484
}
25112485

2512-
Properties.SetColor(s_propFormCaptionBackColor, value);
2513-
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR, value);
25142486
OnFormCaptionBackColorChanged(EventArgs.Empty);
25152487
}
25162488
}
@@ -2537,35 +2509,19 @@ protected virtual void OnFormCaptionBackColorChanged(EventArgs e)
25372509
[Experimental(DiagnosticIDs.ExperimentalDarkMode, UrlFormat = Application.WinFormsExperimentalUrl)]
25382510
public Color FormCaptionTextColor
25392511
{
2540-
get
2541-
{
2542-
if (Properties.ContainsObject(s_propFormCaptionTextColor))
2543-
{
2544-
return Properties.GetColor(s_propFormCaptionTextColor);
2545-
}
2546-
2547-
if (!IsHandleCreated || IsAncestorSiteInDesignMode)
2548-
{
2549-
return Color.Empty;
2550-
}
2551-
2552-
return GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_TEXT_COLOR);
2553-
}
2512+
get => GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_TEXT_COLOR);
25542513
set
25552514
{
25562515
if (value == FormCaptionTextColor)
25572516
{
25582517
return;
25592518
}
25602519

2561-
if (!IsHandleCreated)
2520+
if (IsHandleCreated)
25622521
{
2563-
Properties.SetColor(s_propFormCaptionTextColor, value);
2564-
return;
2522+
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_TEXT_COLOR, value);
25652523
}
25662524

2567-
Properties.SetColor(s_propFormCaptionTextColor, value);
2568-
SetFormAttributeColorInternal(DWMWINDOWATTRIBUTE.DWMWA_TEXT_COLOR, value);
25692525
OnFormCaptionTextColorChanged(EventArgs.Empty);
25702526
}
25712527
}
@@ -2586,7 +2542,7 @@ private unsafe Color GetFormAttributeColorInternal(DWMWINDOWATTRIBUTE dmwWindowA
25862542
{
25872543
COLORREF colorRef;
25882544

2589-
PInvoke.DwmSetWindowAttribute(
2545+
PInvoke.DwmGetWindowAttribute(
25902546
HWND,
25912547
dmwWindowAttribute,
25922548
&colorRef,

0 commit comments

Comments
 (0)