<PackageReference Include="System.Drawing.Common" Version="10.0.0-rc.1.25451.107" />

SaveDcScope

struct SaveDcScope
Helper to scope lifetime of a saved device context state.
using System.Runtime.CompilerServices; namespace Windows.Win32.Graphics.Gdi { [CompilerFeatureRequired("RefStructs")] internal readonly ref struct SaveDcScope { private readonly int _savedState; public HDC HDC { get; } public SaveDcScope(HDC hdc) { _savedState = PInvokeCore.SaveDC(hdc); HDC = hdc; } public void Dispose() { if (_savedState != 0) PInvokeCore.RestoreDC(HDC, _savedState); } } }