Description: This article translated "Debugging Design-Time Controls" from the MSDN website. The original author of the article is Steve Lasker.
Summary: Gradually describe how to debug the custom control of Design-Time in the VS.Net Designer environment, which describe a series of events that may occur when using the design interface operating control.
Introduction
An important part of the custom control development process is the ability to check and debug code. When using the control or Windows Form in the desk-Time environment in VS.NET, your code can be executed even if your project is not running (RUN). This makes this debug code becomes a challenge. If you have created any objects that will be used in Design-Time, this article will tell you when you use these objects in the deskman of VS.NET, and how to debug code. I will also describe a series of events that may occur when using the design interface operating control.
To showcase how you change the value of the control or drag an control to the design interface, we will create a Winform-based example, which has a string property. When we change the value of the property, we will enter the debugger.
Environment
The first step is to build an environment that accommodates our code, we will create:
· An empty solution to accommodate our project
· A control library to accommodate our custom controls
· A WinForm program to use our custom controls
Establish an air solution
1. Click New in the File menu and select Blank Solution.
2. Name the Solution designtimeDebugging
3. Place this Solution in C: / DesigntimeDebugging. As shown below:
Create a space library
Since our goal is to demonstrate how to debug instead of creation custom controls, we don't care about the details created by the control. We will create a simple form with an attribute.
Establish control engineering
1. Click New in the File menu, then click Project.
2. Select Visual C # Projects in the window on the left.
3. Select Windows Control Library in the window on the right.
4. Naming the control library is immedient.windows.forms, note that we keep the same naming rules as Microsoft, and the only difference is that we use "immedient" instead of "system". This defines a unique namespace.
5. Remove userControl1.
Add a new Form
1. Right click on the Control Library Engineering, click Add, then click Add Windows Form.
2. Name Form "Form".
3. Add the following code in the class definition:
C #
Private string_mytext = "hello";
///
/// a Custom Property Used for this Silly Sample
/// summary>
///
[
Description ("A Custom Property Used for this Silly Sample",
DEFAULTVALUE ("Hello"),
Category ("APPEARANCE")
]
Public String MyText
{
Get {return_mytext;
set
{
IF (_mytext! = Value)
{
_mytext = value;
}
}
}
Code Description ("A Custom Property Used for this Silly Sample) will add a description of your property below the property page. The text here is usually the same as the XML watching document.
DefaultValue ("Hello") defines the default value for our attributes. If the value of the attribute is different from DefaultValue, the property page will display this value in a black body. At the same time, VS.NET will also generate the code for setting the value in InitializationComponent (). This is very easy to inherit. If there is no derived class change attribute, they will inherit changes from the base class.
Category ("APPEARANCE") is used to sort attributes in the property page.
to be continued……