.net Form.OnVisibleChanged中的NullReferenceException

.net Form.OnVisibleChanged中的NullReferenceException,.net,winforms,.net,Winforms,在某些计算机上,每次使用此调用堆栈打开某些窗体时,Windows窗体应用程序都会崩溃: Object reference not set to an instance of an object. at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e) at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms

在某些计算机上,每次使用此调用堆栈打开某些窗体时,Windows窗体应用程序都会崩溃:

Object reference not set to an instance of an object.
   at System.Windows.Forms.Form.OnVisibleChanged(EventArgs e)
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at DevExpress.XtraEditors.XtraForm.WndProc(Message& msg)
   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.Forms.Control”派生而来时,应用程序会在
窗体中崩溃。OnVisibleChanged


这显然是Windows窗体中的一个错误,并没有说
IButtonControl AcceptButton
必须派生自
Control

空引用异常通常并不表示继承性不好,正如您在回答中建议的那样。您是否实现了Form.OnVisibleChanged,如果是,我们可以查看您的代码吗?不,该方法未被重写。问题是
Control Control=this.AcceptButton as Control
没有进一步的空检入
表单。OnVisibleChanged
实现(在分支中,如果在鼠标设置中启用,则更改鼠标光标位置)它说:“允许控件像按钮一样工作”。考虑到结果,我想说“控制”这个词的含义是非常清楚的。尽管如此,在一些不太可能的情况下抛出NullReferenceException远非强制执行这一文档化要求的最佳方式。