jon*_*ten 5 .net c# icons system.drawing exception
在Windows XP计算机上,以下代码抛出System.ComponentModel.Win32Exception,并显示消息"操作已成功完成"
System.Drawing.Icon icon = new System.Drawing.Icon("icon.ico");
Run Code Online (Sandbox Code Playgroud)
我可以阻止程序崩溃
try
{
System.Drawing.Icon icon = new System.Drawing.Icon("icon.ico");
}
catch(System.ComponentModel.Win32Exception ex)
{
if (ex.NativeErrorCode != 0)
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
但当然没有设置图标.
完整的堆栈跟踪是
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at System.Drawing.Icon..ctor(String fileName, Int32 width, Int32 height)
at System.Drawing.Icon..ctor(String fileName)
at hermes.Window1..ctor() in D:\\projects\\hermesclient\\hermesWPF\\hermes\\Window1.xaml.cs:line 50"
Run Code Online (Sandbox Code Playgroud)
第50行是我发布的原始行.
这是一个WPF应用程序,在Windows 7机器上,代码工作正常.
编辑:原来这个图标在Windows XP中根本不起作用,添加256色版本似乎已经修复了它.