그래서 전역 변수로 자동 생성되는 일부 클래스 (예 : 정적 인스턴스)를 통해 자동 초기화가 이루어지는 프로젝트가 있습니다. 이 내부의 한 지점 (사용자를위한 C# GUI와 관계가 없으므로 C# 클래스에서 파생되지 않습니다) 플래그가 설정되었는지 확인해야합니다.WinForms Menu Toolstrip 상태 가져 오기
플래그를 설정 또는 설정 해제하기 위해 검사 및 검사되지 않은 상태의 도구 상자 메뉴를 사용합니다. 문제는이 정적 클래스에서 플래그가 선택되었는지 여부를 확인하는 데 어려움이 있습니다. 내 수업은 다른 프로젝트/네임 스페이스 안에 있으며 나중에 응용 프로그램의 GUI에 연결된 DLL이 만들어집니다. GUI는이 Manager 클래스에 따라 다르므로 GUI에서 종속되도록 Manager 클래스를 만드는 것은 옵션이 아닙니다. 그럼에도 불구하고, 나는 그 국가의 이름을 아는 것 또는 다른 수단을 통해 볼 수 있어야한다. 나는 다음을 시도했다 :
if(Application.OpenForms[0].Owner.Controls["_useLocalImageForInitToolStripMenuItem"].Enabled)
{ };
이제 문제는 상위 코드 스 니펫에서 나는 더러운 오류가 발생한다는 것이다. 그러면 어떻게해야합니까?
ToolStrip에 메뉴 : 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
나는 내 노트북에서 문제를 재현 할 수 없기 때문에 오류 메시지를 나중에 게시 할 것이다. 그러나 사무실에 들어가야하지만 근본적으로 불쾌한 예외 처리가되어서 찾을 수 없다. – Yeti