本文整理匯總了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;
}