public static void SetElevationRequiredState(this ButtonBase btn, bool required = true) { if (System.Environment.OSVersion.Version.Major >= 6) { const uint BCM_SETSHIELD = 0x160C; //Elevated button btn.FlatStyle = required ? FlatStyle.System : FlatStyle.Standard; Microsoft.Win32.NativeMethods.SendMessage(btn.Handle, BCM_SETSHIELD, IntPtr.Zero, required ? new IntPtr(1) : IntPtr.Zero); btn.Invalidate(); } else { throw new PlatformNotSupportedException(); } }
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(); } }
/// <summary> /// Sets the state of the elevation required. /// </summary> /// <param name="btn">The BTN.</param> /// <param name="required">if set to <c>true</c> [required].</param> /// <param name="vistaIsSupported">if set to <c>true</c> [vista is supported].</param> /// <exception cref="PlatformNotSupportedException"></exception> public static void SetElevationRequiredState(this ButtonBase btn, bool required = true, bool vistaIsSupported = true) { if (GlobalMethodsStatic.CheckIfTargetPlatformIsSupported(vistaIsSupported)) { if (GlobalMethodsStatic.GetIsTargetPlatformSupported()) { // Elevated button const uint BCM_SETSHIELD = 0x160C; btn.FlatStyle = required ? FlatStyle.System : FlatStyle.Standard; NativeMethods.SendMessage(btn.Handle, BCM_SETSHIELD, IntPtr.Zero, required ? new IntPtr(1) : IntPtr.Zero); btn.Invalidate(); } else { throw new PlatformNotSupportedException(); } } }