所以我有一個項目,通過一些自動創建的類作爲全局變量進行自動初始化(是的,它們是靜態實例)。在這裏面的一點(它與用戶的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