【译】SystemIcons.Shield
2009-04-09 14:29 Kaedei 阅读(515) 评论(0) 编辑 收藏 举报译自DanielMoth的博客,老文章了……
为了锻炼自己的英文水平而翻译。如有翻译得不妥当之处欢迎提出,本人感激不尽
原文链接:http://www.danielmoth.com/Blog/2007/12/systemiconsshield.html
经验丰富的Windows窗体开发人员会对具有很多属性并返回标准系统图标的 System.Drawing.SystemIcons 类感到十分熟悉。如果你能引发一个窗体上的图片框和一个按钮的事件处理程序,那么下面的代码将会让你把SystemIcons用得更好:
C#代码:
void button1_Click(System.Object sender, System.EventArgs e) { // use Error pictureBox1.Image = Bitmap.FromHicon(SystemIcons.Error.Handle); // use Warning this.Icon = SystemIcons.Warning; // use Information int h = button1.ClientSize.Height / 2; Icon ico = new Icon(SystemIcons.Information, h, h); Bitmap bitmap1 = Bitmap.FromHicon(ico.Handle); button1.Image = bitmap1; button1.ImageAlign = ContentAlignment.MiddleLeft; }
VB.NET代码:
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' use Error pictureBox1.Image = Bitmap.FromHicon(SystemIcons.Error.Handle) ' use Warning Me.Icon = SystemIcons.Warning ' use Information Dim h = Button1.ClientSize.Height / 2 Dim ico = New Icon(SystemIcons.Information, h, h) Dim bitmap1 = Bitmap.FromHicon(ico.Handle) Button1.Image = bitmap1 Button1.ImageAlign = ContentAlignment.MiddleLeft End Sub
在.NET Framework 2.0版本的SP1中,我们在这个类中获得了一个新的成员:SystemIcons.Shield。这样的话,如果你正在使用Windows Vista并且工作在用户账户控制(User Account Control)之下,那么你会发现它是一个很有用的图标(例如放在菜单栏上)
下面是使用了上面的代码后点击按钮前后的截图,下方的截图使用了盾牌(Shield)图标替换掉了原来的三个图标。