2013-06-01 126 views
1

我正在尝试调整SystemIcon以便在ErrorProvider中使用。调整ErrorProvider的系统图标

Dim WarnProvider As New ErrorProvider 
    WarnProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink 
    WarnProvider.Icon = SystemIcons.Information.Clone() 
    WarnProvider.Icon.Size = New Size(16,16) 

但SystemIcons的大小设置为只读属性。

在过去的一个小时里,它已经搞乱了它,并没有找到任何好的方法来完成这项工作。

有人可以帮忙吗?

感谢

回答

2

我一直在寻找一种方法来做到这一点,并遇到这篇文章。以下是我最终解决问题的方法。

我创建了一个全局静态方法来调整图标的大小。

public static class Global 
{ 
    public static Icon ResizeIcon(Icon icon, Size size) 
    { 
     Bitmap bitmap = new Bitmap(size.Width,size.Height); 
     using(Graphics g = Graphics.FromImage(bitmap)) 
     { 
      g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 
      g.DrawImage(icon.ToBitmap(), new Rectangle(Point.Empty,size)); 
     } 
     return Icon.FromHandle(bitmap.GetHicon()); 
    } 
} 

然后我在调用InitializeComponent()后在表单的构造函数中应用了图标。

public SpecificationsDialog(int pid) 
{ 
    InitializeComponent(); 
    warningProvider1.Icon = Global.ResizeIcon(SystemIcons.Warning,SystemInformation.SmallIconSize); 
}