在 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);
}
Thanks!
正如 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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)