【发布时间】:2010-03-23 14:34:52
【问题描述】:
所以我有一个项目,其中通过一些作为全局变量自动创建的类进行一些自动初始化(是的,它们是静态实例)。在此内部的某个点(它与用户的 C# GUI 无关,因此它不是从任何 C# 类派生的)我需要查看是否设置了标志。
我使用带有选中和未选中状态的工具条菜单来设置或取消设置标志。问题是我很难从这个静态类中查看是否检查了标志。我的类在不同的项目/命名空间中,并创建了一个 DLL,稍后链接到应用程序的 GUI。 GUI 依赖于此 Manager 类,因此不能选择使 Manager 类依赖于 GUI。尽管如此,我应该能够知道它的名字或通过其他方式看到它的状态。我尝试了以下方法:
if(Application.OpenForms[0].Owner.Controls["_useLocalImageForInitToolStripMenuItem"].Enabled)
{ };
现在的问题是,在上面的代码 sn-p 上我得到了一个讨厌的错误。那我该怎么做呢?
错误:
请参阅此消息的末尾以获取 即时调用的详细信息 (JIT) 调试而不是此对话框 盒子。
**************异常文本************** System.ArgumentOutOfRangeException: 指数超出范围。一定是 非负且小于 集合。参数名称:索引 在 System.Collections.ArrayList.get_Item(Int32 指数)在 System.Windows.Forms.FormCollection.get_Item(Int32 指数)在 Manager.MyMainManager.MyMainManager.RealTimeInit() 在 C:\Dropbox\我的 Dropbox\公共\程序 代码\RoboCup\Manager\MyMainManager\MyMainManager.cs:line 494 在 mainApp.MainForm.ButtonInitClick(对象 发件人,EventArgs e) 在 C:\Dropbox\My Dropbox\公共\程序 代码\RoboCup\mainApp\MainForm.cs:line 389 在 System.Windows.Forms.Control.OnClick(EventArgs 吃 System.Windows.Forms.Button.OnClick(EventArgs 吃 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs 事件)在 System.Windows.Forms.Control.WmMouseUp(消息& m,MouseButtons 按钮,Int32 点击) 在 System.Windows.Forms.Control.WndProc(消息& m) 在 System.Windows.Forms.ButtonBase.WndProc(消息& m) 在 System.Windows.Forms.Button.WndProc(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr 参数)
与private System.Windows.Forms.ToolStripMenuItem _useLocalImageForInitToolStripMenuItem;
this._useLocalImageForInitToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this._useLocalImageForInitToolStripMenuItem.Name = "_useLocalImageForInitToolStripMenuItem";
this._useLocalImageForInitToolStripMenuItem.Size = new System.Drawing.Size(242, 22);
this._useLocalImageForInitToolStripMenuItem.Text = "Use local image for Initialization";
this._useLocalImageForInitToolStripMenuItem.Click += new System.EventHandler(this.
【问题讨论】:
-
你能复制你得到的错误信息吗?
-
我稍后会发布错误消息,因为我无法在笔记本电脑上重现该问题,我需要去办公室,但基本上是一种令人讨厌的未处理异常,抱怨他找不到它。
标签: c# winforms visibility toolstrip