Using C# and .Net 4.0 in a winforms application: Is it possible to add the UAC shield to a button and retain the buttons background image? How?
This is what I'm using at the moment, but it removes the image...
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
public static void UACToButton(Button button, bool add)
{
const Int32 BCM_SETSHIELD = 0x160C;
if (add)
{
// The button must have the flat style
button.FlatStyle = FlatStyle.System;
if (button.Text == "")
// and it must have text to display the shield
button.Text = " ";
SendMessage(button.Handle, BCM_SETSHIELD, 0, 1);
}
else
SendMessage(button.Handle, BCM_SETSHIELD, 0, 0);
}
Thanks!
Perhaps this will help: http://blog.csharphelper.com/2011/03/03/add-uac-shields-to-buttons-menu-items-and-picture-boxes-in-c.aspx
It takes the UAC shield and returns a bitmap that can be placed on anything that supports bitmaps.
EDIT: Here's some rough sample code that could work:
This is drawing the UAC shield over the background image. You can adjust the image location on top of the button. It doesn't look as pretty as the System UAC shield, but it does show the UAC shield icon on top of your background image.
As Elmue mentioned, SystemIcons.Shield is the easiest way to access the UAC Shield icon. Here's the method that I use to add it on top of other images: