Tracking code during design

zhaozj2021-02-16  76

Transfer from http://www.cnblogs.com/dahuzizyd/articles/14045.aspx

Problem in the development: The base class form is defined in the WinForm window. When you open the sub-form in the designer, you will have a window that cannot be used in the designer, which happens ... The information of the abnormality, and the form cannot be opened, and there is no way to use the form designer to interface design. But everything is running.

The reason for this problem is to perform its base class when you double-click the form to open in the Solution Explorer, which is to perform some of the code in the parent form, for example:

Create a base class form, named FormBase, build a subclass form formderive, inherited from FORMBASE PUBLIC CLASSMDERIVE: FORMBASE {private system.componentmodel.container components = NULL;

Public formderive () {initializationComponent ();

} .........................}

Then add a post in the constructor of the base class form: public formbase (); messagebox.show ("It's base form!");} Compile, then double-click Formderive in the Solution Explorer Open the designer, then there is a MessageBox pop-up, then display the design interface of Formderive.

Now let the code in the FORMBASE exception, write a code that generates "array crosions"

String [] array = new string [] {"1", "2", "3"}; for (int i = 0; i <= array.length; i ) {messagebox.show (array [i]); } Open the designer again, pop up the dialog, and the designer is blank, prompt: An exception occurs when trying to create an instance of WindowsApplication 12.FormBase. An exception "index exceeds array boundaries." If you insert a code that causes exceptions in the FORMBASE LOAD event, the same phenomenon occurs when using the designer.

If the code in the base class is relatively simple, you can find a problem with reading, then the code is more complicated? I just said that the topic is now. A debug tool DBGCLR.EXE is provided in .NET, it can track the code in the designer. If you can't find this file, you can use the "Search File" to find it. Here's how to use DBGCLR tracking: Run DBGCLR.EXE Click on the menu: Tool-debugging process, will list the current system's process. Select the DEVENV.EXE process, that is, the vs.net integrate development environment, point addition. Close the dialog. Open the .cs file you want to debug in DBGCLR, where you choose the formBase.cs file and then add a breakpoint to the FORMBASE constructor. Re-open Formderive, when interrupt in DBGCLR, you can debug.

Summary: I have encountered such a form that does not open, it is important to read some configuration files, that is, there is no specified file under the path specified by the design period, but use the generation after the runtime. Copy came over, so there is no problem in the running period.

This problem has been a half-day, knowing the method of debugging, and then there is no fear.

转载请注明原文地址:https://www.9cbs.com/read-16140.html

New Post(0)