所以我有一个项目,通过一些自动创建的类作为全局变量进行自动初始化(是的,它们是静态实例)。在这里面的一点(它与用户的C#GUI没有关系,所以它不是从任何C#类派生的)我需要看看是否设置了一个标志。WinForms菜单工具条获取状态
我使用带有选中和未选中状态的工具栏菜单来设置或取消设置标志。问题是,我很难从该静态类中查看标志是否被选中。我的类位于不同的项目/名称空间中,并且创建了一个DLL,该DLL随后会链接到应用程序的GUI。 GUI依赖于此Manager类,因此使Manager类不依赖于GUI而不是选项。不过,我应该能够看到其状态知道它的名字或通过其他方式。我曾尝试以下:
if(Application.OpenForms[0].Owner.Controls["_useLocalImageForInitToolStripMenuItem"].Enabled)
{ };
现在的问题是,在上代码片段,我得到一个讨厌的错误。那么,我该如何做到这一点?
的工具条菜单: alt text http://img251.imageshack.us/img251/6473/imagetoolstrip.jpg
错误:
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text ************** System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.Collections.ArrayList.get_Item(Int32 index) at System.Windows.Forms.FormCollection.get_Item(Int32 index) at Manager.MyMainManager.MyMainManager.RealTimeInit() in C:\Dropbox\My Dropbox\Public\Program Code\RoboCup\Manager\MyMainManager\MyMainManager.cs:line 494 at mainApp.MainForm.ButtonInitClick(Object sender, EventArgs e) in C:\Dropbox\My Dropbox\Public\Program Code\RoboCup\mainApp\MainForm.cs:line 389 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.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)
alt text http://img185.imageshack.us/img185/2734/20100323095952.png
随着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.
你能复制你收到的错误信息吗? – FOR 2010-03-23 14:37:02
我稍后会发布错误消息,因为我无法在笔记本电脑上重现问题,而且我需要进入办公室,但基本上是一种令人讨厌的未处理异常,抱怨他无法找到它。 – Yeti 2010-03-23 14:51:59