using System;
using System.Windows.Forms;
using static Vanara.PInvoke.User32;
namespace Vanara.Extensions
{
/// Extension methods for .
public static partial class ButtonExtension
{
/// Sets a value that determines if the shield icon is shown on the button to indicate that elevation is required.
/// The instance.
///
/// If set to , the shield icon will be shown on the button. If , the button will
/// display normally.
///
/// This method is only support on Windows Vista and later.
public static void SetElevationRequiredState(this ButtonBase btn, bool required = true)
{
if (Environment.OSVersion.Version.Major >= 6)
{
if (!btn.IsHandleCreated) return;
if (required) btn.FlatStyle = FlatStyle.System;
SendMessage(btn.Handle, (uint)ButtonMessage.BCM_SETSHIELD, IntPtr.Zero, required ? new IntPtr(1) : IntPtr.Zero);
btn.Invalidate();
}
else
throw new PlatformNotSupportedException();
}
}
}