using System.Drawing;
using Vanara.Interop;
namespace System.Windows.Forms.VisualStyles
{
internal static partial class VisualStyleRendererExtension
{
public static Padding GetMargins2(this VisualStyleRenderer rnd, IDeviceContext dc = null, MarginProperty prop = MarginProperty.ContentMargins)
{
NativeMethods.RECT rc;
using (var hdc = new NativeMethods.SafeDCHandle(dc))
NativeMethods.GetThemeMargins(rnd, hdc, rnd.Part, rnd.State, (int)prop, IntPtr.Zero, out rc);
return new Padding(rc.Left, rc.Top, rc.Right, rc.Bottom);
}
public static int GetTransitionDuration(this VisualStyleRenderer rnd, int toState, int fromState = 0)
{
int dwDuration;
NativeMethods.GetThemeTransitionDuration(rnd, rnd.Part, fromState == 0 ? rnd.State : fromState, toState, (int)NativeMethods.IntegerListProperty.TransitionDuration, out dwDuration);
return dwDuration;
}
///
/// Sets the state of the .
///
/// The instance.
/// The state.
public static void SetState(this VisualStyleRenderer rnd, int state) { rnd.SetParameters(rnd.Class, rnd.Part, state); }
///
/// Sets attributes to control how visual styles are applied to a specified window.
///
/// The window.
/// The attributes to apply or disable.
/// if set to true enable the attribute, otherwise disable it.
public static void SetWindowThemeAttribute(this IWin32Window window, NativeMethods.WindowThemeNonClientAttributes attr, bool enable = true)
{
try { NativeMethods.SetWindowThemeAttribute(window, attr, enable ? (int)attr : 0); }
catch (EntryPointNotFoundException) { }
}
}
}