Skip to content

Commit 87a751d

Browse files
Add docs and serialization handling.
1 parent 2f070a5 commit 87a751d

File tree

1 file changed

+41
-16
lines changed
  • src/System.Windows.Forms/System/Windows/Forms

1 file changed

+41
-16
lines changed

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

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,11 +1725,43 @@ internal override Control? ParentInternal
17251725
}
17261726

17271727
/// <summary>
1728-
/// If ShowInTaskbar is true then the form will be displayed in the Windows Taskbar.
1728+
/// Gets or sets the behavior for preventing screen capture/video recording of the
1729+
/// form's content via screen capture applications based on the Windows APIs.
17291730
/// </summary>
1730-
[DefaultValue(0)]
1731+
/// <remarks>
1732+
/// <para>
1733+
/// This property determines how the form's content behaves when captured by screen capture applications
1734+
/// or screenshots. Different capture modes provide varying levels of privacy and security for sensitive content.
1735+
/// </para>
1736+
/// <para>
1737+
/// By default, forms allow their content to be captured. Setting this property to a more restrictive value
1738+
/// can prevent sensitive information from being captured in screenshots or recorded in screen recordings.
1739+
/// </para>
1740+
/// <para>
1741+
/// The setting takes effect immediately for visible forms. For forms that aren't yet shown,
1742+
/// the setting takes effect when the form becomes visible.
1743+
/// </para>
1744+
/// <para>
1745+
/// Warning! Additional top-level window, which will be spinning off the form, will not be affected
1746+
/// by this setting. Please be aware, that for example sensitive information in a pop-up window
1747+
/// like a MessageBox, a context menu, DropDownButton menus or PullDown-menus can not be prevented
1748+
/// from being captured!
1749+
/// </para>
1750+
/// <para>
1751+
/// Note that this setting only affects the current form and not any other windows in the application.
1752+
/// Also note that this will also affect video streaming applications for video conferencing, etc.
1753+
/// </para>
1754+
/// <para>
1755+
/// Disclaimer: Please keep in mind, that this setting can of course not prevent screen recordings by tools,
1756+
/// which are either circumvent the public Windows APIs or use hardware-based screen capture methods.
1757+
/// </para>
1758+
/// </remarks>
1759+
/// <value>
1760+
/// One of the <see cref="ScreenCaptureMode"/> enumeration values. The default is
1761+
/// <see cref="ScreenCaptureMode.Allow"/>.
1762+
/// </value>
17311763
[SRCategory(nameof(SR.CatWindowStyle))]
1732-
[SRDescription("")]
1764+
[SRDescription(nameof(SR.FormScreenCaptureModeDescr))]
17331765
public ScreenCaptureMode FormScreenCaptureMode
17341766
{
17351767
get => _formScreenCaptureMode;
@@ -1749,6 +1781,12 @@ public ScreenCaptureMode FormScreenCaptureMode
17491781
}
17501782
}
17511783

1784+
private bool ShouldSerializeFormScreenCaptureMode() =>
1785+
FormScreenCaptureMode != ScreenCaptureMode.Allow;
1786+
1787+
private void ResetFormScreenCaptureMode() =>
1788+
FormScreenCaptureMode = ScreenCaptureMode.Allow;
1789+
17521790
private void SetScreenCaptureModeInternal(ScreenCaptureMode value)
17531791
{
17541792
if (!TopLevel)
@@ -1767,19 +1805,6 @@ private void SetScreenCaptureModeInternal(ScreenCaptureMode value)
17671805
PInvoke.SetWindowDisplayAffinity(HWND, affinity);
17681806
}
17691807

1770-
private ScreenCaptureMode GetScreenCaptureModeInternal()
1771-
{
1772-
PInvoke.GetWindowDisplayAffinity(HWND, out uint affinityValue);
1773-
WINDOW_DISPLAY_AFFINITY affinity = (WINDOW_DISPLAY_AFFINITY)affinityValue;
1774-
1775-
return affinity switch
1776-
{
1777-
WINDOW_DISPLAY_AFFINITY.WDA_EXCLUDEFROMCAPTURE => ScreenCaptureMode.HideWindow,
1778-
WINDOW_DISPLAY_AFFINITY.WDA_MONITOR => ScreenCaptureMode.HideContent,
1779-
_ => ScreenCaptureMode.Allow,
1780-
};
1781-
}
1782-
17831808
/// <summary>
17841809
/// If ShowInTaskbar is true then the form will be displayed in the Windows Taskbar.
17851810
/// </summary>

0 commit comments

Comments
 (0)