我正在支持使用 dotnet 3.5 和 ComponentFactory Krypton v4.4.0.0 的 winforms 应用程序,我最近实现了 AppDomain.CurrentDomain.UnhandledException 和 Application.ThreadException 处理程序来通知我客户端上发生的异常,并发现出现了很多错误在日志中。这个现在正在我的脑海中:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Font.GetHeight(Graphics graphics)
at System.Drawing.Font.GetHeight()
at System.Drawing.Font.get_Height()
at System.Windows.Forms.Control.set_Font(Font value)
at System.Windows.Forms.DataGridViewComboBoxEditingControl.ApplyCellStyleToEditingControl(DataGridViewCellStyledataGridViewCellStyle)
at System.Windows.Forms.DataGridView.BeginEditInternal(Boolean selectAll)
at System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam,IntPtr lparam)
请注意,堆栈跟踪完全在 Windows 代码中。还有一个通过我的一个课程:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Font.GetHeight(Graphics graphics)
at System.Drawing.Font.GetHeight()
at System.Drawing.Font.get_Height()
at System.Windows.Forms.Control.set_Font(Font value)
at MyOrg.MyApp.WindowsClient.GuiControls.MaskedTextBoxEditingControl.ApplyCellStyleToEditingControl(DataGridViewCellStyledataGridViewCellStyle)
at System.Windows.Forms.DataGridView.BeginEditInternal(Boolean selectAll)
at System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
这是该片段的代码:
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
this.Font = dataGridViewCellStyle.Font;
this.ForeColor = dataGridViewCellStyle.ForeColor;
this.BackColor = dataGridViewCellStyle.BackColor;
this.TextAlign = translateAlignment(dataGridViewCellStyle.Alignment);
}
这并没有告诉我太多。
“System.ArgumentException:参数无效。” 错误是非常可悲的,给我的余地很少,但是使用 dotPeek 我查看了 Font.Get_Height(Graphics g) 的代码,发现这是一个 GDI+ 错误,特别是 GetFontHeight:
public float GetHeight(Graphics graphics)
{
if (graphics == null)
{
throw new ArgumentNullException("graphics");
}
else
{
float size;
int fontHeight = SafeNativeMethods.Gdip.GdipGetFontHeight(new HandleRef((object) this, this.NativeFont), new HandleRef((object) graphics, graphics.NativeGraphics), out size);
if (fontHeight != 0)
throw SafeNativeMethods.Gdip.StatusException(fontHeight);
else
return size;
}
}
这是 GDI+ 方法: http ://www.jose.it-berater.org/gdiplus/reference/flatapi/font/gdipgetfontheight.htm
我的状态错误是无效参数,如此处所述:http: //msdn.microsoft.com/en-us/library/windows/desktop/ms534175 (v=vs.85) .aspx
不幸的是,这些都不能帮助我解决 Graphics 对象的问题。这是来自现场用户未处理的异常。我最近有一个内存泄漏,这是由泄漏的 EventHandler 和消耗所有可用的 GDI 句柄引起的,但我已经修复了这个问题,所以现在我不确定这是内存泄漏、GDI 句柄泄漏还是只是坏的配置某个由用户做一些不寻常的事情触发的地方。
有人有想法么?非常感谢帮助!