本文整理汇总了C#中System.Windows.Forms.Button.SetShieldIcon方法的典型用法代码示例。如果您正苦于以下问题:C# Button.SetShieldIcon方法的具体用法?C# Button.SetShieldIcon怎么用?C# Button.SetShieldIcon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Button
的用法示例。
在下文中一共展示了Button.SetShieldIcon方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUacShieldIcon
// Technique from http://www.vb-helper.com/howto_2008_uac_shield.html
private Bitmap GetUacShieldIcon()
{
const int width = 50;
const int height = 50;
const int margin = 4;
Bitmap shieldImage;
Button button = new Button()
{
Text = " ",
Size = new Size(width, height),
FlatStyle = FlatStyle.System
};
button.SetShieldIcon(true);
Bitmap buttonImage = new Bitmap(width, height);
button.Refresh();
button.DrawToBitmap(buttonImage, new Rectangle(0, 0, width, height));
int minX = width;
int maxX = 0;
int minY = width;
int maxY = 0;
for (int y = margin; y < height - margin; y++)
{
var targetColor = buttonImage.GetPixel(margin, y);
for (int x = margin; x < width - margin; x++)
{
if (buttonImage.GetPixel(x, y).Equals(targetColor))
{
buttonImage.SetPixel(x, y, Color.Transparent);
}
else
{
if (minY > y) minY = y;
if (minX > x) minX = x;
if (maxY < y) maxY = y;
if (maxX < x) maxX = x;
}
}
}
int shieldWidth = maxX - minX + 1;
int shieldHeight = maxY - minY + 1;
shieldImage = new Bitmap(shieldWidth, shieldHeight);
using (Graphics g = Graphics.FromImage(shieldImage))
g.DrawImage(buttonImage, 0, 0, new Rectangle(minX, minY, shieldWidth, shieldHeight), GraphicsUnit.Pixel);
buttonImage.Dispose();
return shieldImage;
}