Create a WinForm project for applying custom controls
1. Click New in the File menu, then click Project.
2. Select Visual C # Projects in the window.
3. Select Window Application in the window on the right (this application will apply our example).
4. Name the engineering designtimedebugging.
5. Determine the radio button to select Add to Solution.
Add our control library to the project
1. In our Host App Project, right-click References, click Add Reference.
2. On the Projects property page, select the Immediate.Windows.Forms project.
Use our custom Form
1. In order to be able to use Microsoft IntelliSense, we recompile our project.
2. Use the following code to change the inheritance relationship of FORM1, and change it by our custom Form derived.
C #
Namespace immedient.samples.hostapp.windows
{
Public class form1: immedient.windows.forms.form
{
3. Open FORM1, we will find that our custom properties appear on the property page. If there is an error, close all on-the-loop files, then Rebuild Solution, reopen Form1.
Set the properties of the control library project
Usually we want to determine if we have information needed to debug our code in VS.NET. When you start debugging, if you open to "?" Symbol on the breakpoint, we don't have a suitable symbol file. This may be due to the current release mode, or the engineering setting is accidentally changed. It should be determined that the generate debugging information property is set to TRUE.
XML document (C # ONLY)
The following settings are only valid for C #, in VS.NET2002, VB.NET does not generate an XML document.
In order to benefit from our XML annotations created in the C # code, we should tell VS.NET to generate an XML document. Set the XML Documentation File property to the same value as an XML suffix with the namembly name.
Here is a tip of XML documents. Once you set XML Documentation File, VS.NET will help you cause warnings for each public interface that doesn't have an XML annotation. These warnings sometimes annoying. If you haven't prepared to process all public interface documents, you can set WARNING Level to 2, so that the task list will not collect warning information until you have all things to be prepared, set it back. I.e.
Start debugging
Now we have some code that you can debug, let's get started. In order to debug our code, we need to enter the application of our code (STEP INTO). In our example is VS.NET.
Set debug properties
In the debugging process, we need to change some debug properties. They differ in VB.NET and C # (translation: I have to be c # as an example).
C # Engineering Properties Page
1. Right click on the Control Library project and select Property.
2. Click Configuration Properties.
3. Change Debug Mode to Program. 4. Change the Start Application to Visual Studio .NET. The default location is: C: / Program Files / Microsoft Visual Studio .NET / Common7 / IDE / DEVENV.EXE.
Set breakpoint
Set breakpoints on the IF expression in the set of custom properties
Last one
Make sure the Control Library project is a startup project. Right-click on the Control Library Engineering to select Set as Startup Project.
continue
1. Press F5 to start the debugging process. At this time, there will be a new VS.NET instance to be started, and our development environment masters this instance --pretty cool.
2. Sover, which vs.net is a convenient way to our debugging environment is to see the debug button. Start Button in the debug environment is invalid.
3. When the new vs.net starts, open the same Solution: c: c: /designtimedebugging/designtimedebugging.sln
4. In the HostApp Windows Forms project, double-click Form1 to open.
5. In the property page, change the value of the MyText property is Good Bye.
6. At this point, you should step into the breakpoint.
7. We have debugged our first .NET Design-Time Control. Now let's take a look at a series of events that happen in the background.
Event chain
When using the design, when you drag a control to the design interface, it understands what happens behind it. You must know what it happened when you create another form derived from another form you created.
When an object is opened in the design environment, the class inherited by this object (not a newly generated class) is constructed by the VS.NET. Remember, this created control activation (Fire) its constructor, the constructor activates the initializationComponent () method in the constructor of its base class. Once derived class is constructed, the method of having a magical name in the new class, INITIALIZEComponent () will be parsed by VS.NET. This method is the only magical thing is its name because VS.NET knows to find this method.
In VB.NET, if VS.NET cannot parse a row code, then this line will be deleted. At this time, the environment is more important because the VB development team feels that the environment is maintained. The C # Development team believes that keep the code more important, so in C #, if VS.NET cannot parse initializeComponent (), you will get a text that describes exceptions.
When initializeComponent () is running, the value of the property will be changed to the value you set on the property page. In VS.NET, the object page of the object is just a graphical representation of the initializationComponent () method. If your base class constructor is to complete some special features, be careful, these features are also designed to be executed.
There is a way to make these code not being executed when designing. Any Class, which is sent from the Component class has a DesignMode property. This property is set to True when the object is constructed in VS.NET Designer. So you can write an IF to package your code, avoiding them being performed. But there is no more tricks, and DesignMode will not be set to True in the function. Remember, there is no magic here. VS.NET constructs objects by parsing the InitializationComponent () method, once the object is constructed, VS.NET will keep track of the object and simply set: newlycreatedObject.designMode = true
In order to add some fun, what are the events in things happen, and when DesignMode is set, add the following code in your immedient.windows.forms.form (Translation: Please add events with vs.net, this You can guarantee that the event is properly added to the InitializationComponent method). In order to get an event issued by VS.NET, close all FORM, recompile Solution.
Private Void Form_Layout (Object Sender, System.Windows.Forms.LayouteventArgs E)
{
Messagebox.show ("layout: designmode =" this.designmode.toString ());
}
Private Void Form_Load (Object Sender, System.Eventargs E)
{
IF (this.Designmode)
{
// Don't connect to Database.
Messagebox.show ("form: designmode =" this.designmode.toTRING ());
}
Else
{
// Make a connection to database and do something.
Messagebox.show ("form: designmode =" this.designmode.toTRING ());
}
}
Private Void Form_VisibleChanged (Object Sender, System.Eventargs E)
{
Messagebox.show ("VisibleChanged: DesignMode =" this.DesignMode.toTString ());
}
Private void form_paint (Object Sender, System.Windows) E) E.mms.Painteventargs E)
{
Messagebox.show ("Paint: designMode =" this.designmode.toString ());
}
to sum up
In this article, we use a simple attribute on Windows Form. It can be seen that anything changes can be debugged in the design time environment. I originally discovered this trick, when I developed an ASP.NET Image Href design time control. The same techniques are also applicable to system component controls, such as EventLog controls, and DATA controls displayed in the system tray. VS.NET provides a rich, efficient development environment for development controls, here, creating and debugging controls are as simple as destroying them.
About author