在 winforms 应用程序中使用 C# 和 .Net 4.0:是否可以将 UAC 屏蔽添加到按钮并保留按钮背景图像?怎么办?
这就是我目前正在使用的,但它删除了图像...
[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);
}
谢谢!
最佳答案
正如 Elmue 提到的,SystemIcons.Shield 是访问 UAC Shield 图标的最简单方法。这是我用来将它添加到其他图像之上的方法:
public static Image AddUACShieldToImage(Image image)
{
var shield = SystemIcons.Shield.ToBitmap();
shield.MakeTransparent();
var g = Graphics.FromImage(image);
g.CompositingMode = CompositingMode.SourceOver;
g.DrawImage(shield, new Rectangle(image.Width / 2, image.Height / 2, image.Width / 2, image.Height / 2));
return image;
}
关于c# - 向按钮添加 UAC 屏蔽并保留其背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13758458/