Add simple attributes to a user control
This walkthrough shows how to add properties to a user control in a device project. Specifically, add custom attributes that make the control property visible during design ). You may want to add this feature to the project to prevent attribute values from being changed. This process is similar to the corresponding desktop function, but the device project stores this information in a separate metadata file (. xmta.
Create usercontrol1 class
1. Point to "new" on the "file" menu, and click "project ".
2. In the project type pane, expand Visual C # And smart devices, and then click Pocket PC 2003 ".
3. In the template pane, click control library ".
4. In the "name" box, type "mycontrollibrary" and click "OK ". The designer opens and displays a square representing the new user control class.
Add attribute
1. In Solution Explorer, right-click usercontrol1.cs and click View class relationship diagram on the shortcut menu ". The rounded rectangle representing the class relationship graph is opened.
2. Right-click the class relationship graph and click "class details" in the shortcut menu ".
3. In the "properties" section of the "class details" window, type myproperty at the "<add property>" prompt.
4. In the "type" column, replace "int" with "string ".
5. Right-click the icon starting with "myproperty" and click "properties" in the shortcut menu ".
6. to specify the value of the "custom property" attribute, click the ellipsis (...) To open the "Custom properties" dialog box.
7. Type browsable (false) and click OK ". Solution Explorer displays the design-time property. xmta file (designtimeattributes. xmta) containing the custom property ).
Generate control library
1. In Solution Explorer, right-click usercontrol1.cs and click View code on the shortcut menu ".
2. comment out the row that causes system. notimplementedexception, and insert return ""; as the get operation.
3. Click Generate mycontrollibrary on the generate menu ".
Test whether myproperty is not displayed in the property Browser
1. In Solution Explorer, right-click "mycontrollibrary", point to "add" on the shortcut menu, and click "new item ".
2. In the "Add new project" dialog box, select "Windows form" and click "add ".
3. Drag "usercontrol1" from the "toolbox" to the form.
4. Right-click the user control image on the form and click "properties" on the shortcut menu ". "Myproperty" is not displayed in the "properties" browser.
5. In Solution Explorer, double-click the. xmta file and replace "false" with "true ".
6. Repeat these steps to view the "attribute" grid. Note: "myproperty" is displayed now.
From:
Http://msdn.microsoft.com/zh-cn/learning/ms180789 (vs.80). aspx