在设计器模式下打开窗体窗体时抛出System.Exception类型的异常 [英] An Exception of type System.Exception was thrown while opening a window form in designer mode

查看:163
本文介绍了在设计器模式下打开窗体窗体时抛出System.Exception类型的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在设计器模式下打开已创建的窗体时,抛出了类型System.Exception的异常。当我尝试在设计器模式下打开我已创建的任何窗体时,会出现此问题。我不知道为什么会出现这个错误。我需要编辑我的表单,但我无法这样做..请帮帮我.......



这是设计师调用Stack输出模式.....

An Exception of type System.Exception was thrown when I am trying to open an already created window form in designer mode. This problem is coming when I am trying to open any window form which I have already created, in designer mode. I don't know why this error is coming. I need to edit my forms but I am not able to do so.. Please help me.......

This is the call Stack output in designer mode.....

at VSLangProj.Reference.get_Path() at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_FileName() at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.GetMatchIndex(String typeName) at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchNormalEntries(AssemblyName assemblyName, String typeName, Boolean ignoreTypeCase, Assembly& assembly, Boolean fastSearch) at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchEntries(AssemblyName assemblyName, String typeName, Boolean ignoreCase, Assembly& assembly, ReferenceType refType) at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType) at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase) at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name) at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.GetType(String typeName) at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager) at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager) at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)



下面是其中一个表单的头文件及其C ++文件代码.....



WelcomeWindow.h


Below is one of the form's header file and its C++ file code.....

WelcomeWindow.h

#ifndef WELCOMEWINDOW_H
#define WELCOMEWINDOW_H

#pragma once

#include "test_open.h"
namespace open_image {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for WelcomeWindow
	/// </summary>
	public ref class WelcomeWindow : public System::Windows::Forms::Form
	{
	public:
		WelcomeWindow(void);

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~WelcomeWindow();

	private: System::Windows::Forms::Label^  label1;
	protected: 
	private: System::Windows::Forms::Button^  continue_btn;
	private: System::Windows::Forms::Button^  exit_btn;


	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(WelcomeWindow::typeid));
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->continue_btn = (gcnew System::Windows::Forms::Button());
			this->exit_btn = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->BackColor = System::Drawing::SystemColors::GrayText;
			this->label1->Font = (gcnew System::Drawing::Font(L"Monotype Corsiva", 21.75F, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)), 
				System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
			this->label1->Location = System::Drawing::Point(0, 0);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(136, 36);
			this->label1->TabIndex = 0;
			this->label1->Text = L"Welcome...";
			// 
			// continue_btn
			// 
			this->continue_btn->BackColor = System::Drawing::SystemColors::GrayText;
			this->continue_btn->Font = (gcnew System::Drawing::Font(L"Bookman Old Style", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->continue_btn->Location = System::Drawing::Point(479, 402);
			this->continue_btn->Name = L"continue_btn";
			this->continue_btn->Size = System::Drawing::Size(81, 32);
			this->continue_btn->TabIndex = 1;
			this->continue_btn->Text = L"Continue";
			this->continue_btn->UseVisualStyleBackColor = false;
			this->continue_btn->Click += gcnew System::EventHandler(this, &WelcomeWindow::continue_btn_Click);
			// 
			// exit_btn
			// 
			this->exit_btn->BackColor = System::Drawing::SystemColors::GrayText;
			this->exit_btn->Font = (gcnew System::Drawing::Font(L"Bookman Old Style", 9, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->exit_btn->Location = System::Drawing::Point(560, 402);
			this->exit_btn->Name = L"exit_btn";
			this->exit_btn->Size = System::Drawing::Size(65, 32);
			this->exit_btn->TabIndex = 2;
			this->exit_btn->Text = L"Exit";
			this->exit_btn->UseVisualStyleBackColor = false;
			this->exit_btn->Click += gcnew System::EventHandler(this, &WelcomeWindow::exit_btn_Click);
			// 
			// WelcomeWindow
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
			this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
			this->ClientSize = System::Drawing::Size(630, 441);
			this->Controls->Add(this->exit_btn);
			this->Controls->Add(this->continue_btn);
			this->Controls->Add(this->label1);
			this->Name = L"WelcomeWindow";
			this->Text = L"WelcomeWindow";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void exit_btn_Click(System::Object^  sender, System::EventArgs^  e);
	private: System::Void continue_btn_Click(System::Object^  sender, System::EventArgs^  e);
	};
}
#endif





WelcomeWindow。 cpp



WelcomeWindow.cpp

#include "stdafx.h"
#include "WelcomeWindow.h"
#include "test_open.h"
namespace open_image
{
	WelcomeWindow::WelcomeWindow(void)
	{
		InitializeComponent();
		//
		//TODO: Add the constructor code here
		//
	}
	WelcomeWindow::~WelcomeWindow()
	{
		if (components)
		{
			delete components;
		}
	}
	public ref class container
	{
		public:
			static test_open^ t = gcnew test_open();
	};
	System::Void WelcomeWindow::exit_btn_Click(System::Object^  sender, System::EventArgs^  e) {
		this->Close();
		exit(1);
	}
	System::Void WelcomeWindow::continue_btn_Click(System::Object^  sender, System::EventArgs^  e) {
		/*test_open^ t = gcnew test_open();*/
		this->Hide();
		container::t->Show();
	}
}

推荐答案

this.BackgroundImage)));
- > BackgroundImageLayout = System :: Windows :: Forms :: ImageLayout :: Stretch;
this - > ClientSize = System :: Drawing :: Size( 630 441 );
- > Controls->添加( - > exit_btn);
- > Controls->添加( - > continue_btn);
- > Controls->添加( - > label1);
- >名称= L WelcomeWindow;
this - > Text = L WelcomeWindow;
- > ResumeLayout( false );
- > PerformLayout();

}
#pragma endregion
private : System :: Void exit_btn_Click(System :: Object ^ sender,System :: EventArgs ^ e);
private :System :: Void continue_btn_Click(System :: Object ^ sender,System :: EventArgs ^ e);
};
}
#endif
this.BackgroundImage"))); this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch; this->ClientSize = System::Drawing::Size(630, 441); this->Controls->Add(this->exit_btn); this->Controls->Add(this->continue_btn); this->Controls->Add(this->label1); this->Name = L"WelcomeWindow"; this->Text = L"WelcomeWindow"; this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void exit_btn_Click(System::Object^ sender, System::EventArgs^ e); private: System::Void continue_btn_Click(System::Object^ sender, System::EventArgs^ e); }; } #endif





WelcomeWindow。 cpp



WelcomeWindow.cpp

#include "stdafx.h"
#include "WelcomeWindow.h"
#include "test_open.h"
namespace open_image
{
	WelcomeWindow::WelcomeWindow(void)
	{
		InitializeComponent();
		//
		//TODO: Add the constructor code here
		//
	}
	WelcomeWindow::~WelcomeWindow()
	{
		if (components)
		{
			delete components;
		}
	}
	public ref class container
	{
		public:
			static test_open^ t = gcnew test_open();
	};
	System::Void WelcomeWindow::exit_btn_Click(System::Object^  sender, System::EventArgs^  e) {
		this->Close();
		exit(1);
	}
	System::Void WelcomeWindow::continue_btn_Click(System::Object^  sender, System::EventArgs^  e) {
		/*test_open^ t = gcnew test_open();*/
		this->Hide();
		container::t->Show();
	}
}


最可能的原因

Form.Load事件,从Form.Load事件调用的事件或初始化期间调用的其他一些代码(构造函数?)



解决方案

Form.Load事件在设计模式和运行程序时执行。要防止由Form.Load事件中的代码执行导致的设计模式问题,请执行以下操作:



将所有代码放入Form.Load事件中如果这样的声明:
if (!this->DesignMode) {
//
//
// All of the Form.Load event code goes here
//
//
}





请参阅 DesignMode Property [ ^ ]。

备注

DesignMode属性返回true表示控件正在设计器的上下文中使用。当设计时行为与运行时行为不同时,您的自定义控件可以使用此属性。



See DesignMode Property[^] in the Visual Studio Help.
Remarks
The DesignMode property returns true to indicate that the control is being used in the context of a designer. Your custom controls can use this property when design-time behavior is different than run-time behavior.


在vsprojet中删除文件。

稍后重新加载文件。再试一次。
remove files at the vsprojet.
later reload the files.try again.


这篇关于在设计器模式下打开窗体窗体时抛出System.Exception类型的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆