天天看点

ActiveX Control学习笔记3

Technorati 标签: ActiveX Control, Properties, Methods, Events, Property Pages, Distribution 来自MSDN-2001-OCT: Visual Tools and Languages/Visual Studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/ Component Tools Guide/Creating ActiveX Components/Building ActiveX Controls/Adding Properties to Controls起   1、Saving the Properties of Your Control (1)在Property Let里必须写上PropertyChanged “属性名”。因为控件需要知道自己的值被改变了,以便WriteProperty事件能被正确激发;另外属性值在IDE多处显示,调用这个方法可以让这些显示同步。不过运行时only的属性不需要调用这个方法,除非它是Data-Bound的。 (2)可以设置某个属性不要出现在Property Browser中。 (3)在initializing, saving, and retrieving property values要提供缺省值,以便让容器文件小些(这样容器文件只需要记录和缺省值不一样的值)。 (4)在ReadProperty里要用错误捕获,以防users editing the .frm file with text editors给你传错误的值。 (5)在ReadProperty里把值赋给UserControl的属性,可以引发相应的Let过程里的validation。 (6)Saving and Retrieving Binary Data。介绍了存储二进制属性数据的方法。   2、Exposing Properties of Constituent Controls (1)可以通过委托把UserControl的属性或其构成控件的属性暴露给用户。 (2)可以把一个属性映射到多个构成控件的属性。 (3)不能把控件直接暴露给开发者,编译通不过的。而且这样做有种种设计上的坏处。能暴露的只有public data type和一些标准对象。 (4)Whenever possible, use the standard data types and enumerations provided by Visual Basic as data types of your control's properties. 比如MousePointer,OLE_COLOR, OLE_TRISTATE, OLE_OPTEXCLUSIVE, OLE_CANCELBOOL.   3、和属性相关的其他事情 (1)设置只读属性等:In the Property Let or Property Set procedure, test the UserMode property of the AmbientProperties object. (2)Marking a Property as the Properties Window Default:mark it as the user interface default (3)Grouping Properties by Category:通过简单的设置就行。 (4)通常应该提供的属性:Appearance, BackColor, BackStyle, BorderStyle, Enabled, Font, and ForeColor,以及其他类似控件通常会提供的属性。 (5) Every property or method in your type library has an identification number, called a procedure ID or DISPID. The property or method can be accessed either by name (late binding) or by DISPID (early binding). 对于一些常见的属性和方法,ActiveX规范规定了标准的DISPID,你的方法可以是任意名字,只要用对了DISPID,系统就能正确调用它。 (6)你可以给方法属性设置标准的ProcedureId,否则VB就会自动为它设置一个。 (7)Procedure IDs of Interest:AboutBox, Caption, Text, (Default), Enabled. (8)ActiveX Control Interface Wizard可以简化委托的过程,通过一通设置后,可以帮助你自动生成各种属性和方法对应的代码。 (9)If your control is not invisible at run time, you should provide a Refresh method. This method should simply call UserControl.Refresh. 4、Raising Events from Controls (1)properties and methods as incoming, and events as outgoing. (2)Mouse Events and Translating Coordinates (3)Events the Container Provides for Your Control:GotFocus, LostFocus, DragOver, and DragDrop. 是给开发者用的,而不是给author用的。 (4)Specifying a Default Event for the Code Window:简单设置一哈就成。 (5)Events Your Control Should Raise:Recommended events include Click, DblClick, KeyDown, KeyPress, KeyUp, MouseDown, MouseMove, and MouseUp. 5、Providing Named Constants for Your Control (1)Enum member names are used in the Properties window. 所以,名字虽然要有前缀避免冲突,但是也不要太长否则在属性窗口显示得不好看。 (2)Global objects cannot be used to simulate string constants. 6、Creating Robust Controls Because a control component runs in the process space of an application that uses it, fatal errors in your controls are also fatal errors for the application.

ActiveX Control学习笔记3

    Unhandled errors in event procedures will be fatal to your control component, and the application using it, because there will never be a procedure on the call stack that can handle the errors. In particular, provide thorough error handling in the UserControl's Paint, Resize, and Terminate events. 

ActiveX Control学习笔记3

    如果要暴露构成控件的dependent object,则要wrap it,而不要允许用户直接访问它,那有可能带来危险。比如TreeView的Nodes。 

ActiveX Control学习笔记3

    用Property过程来实现属性,而不要用公共变量。

ActiveX Control学习笔记3

    Debugging Controls: 这一节讲了Debug过程中UserControl的几种状态和会发生的事件。   7、Distributing Controls (1)Creating Setup for ActiveX Control Components:using SetupWizard is recommended. (2)Licensing Issues for Controls:没咋看。 (3)Versioning Issues for Controls:Interface compatibility(接口不能动,或者用新的接口);改动现有接口的时候要充分考虑到已有应用是否仍能正常工作。 (4)Localizing Controls:非常详细的一节,没看。   8、Creating Property Pages for ActiveX Controls (1)How Property Pages Work:The key event for PropertyPage objects is the SelectionChanged event. 这一节详细讲了Property Page的工作过程的各个细节。没咋看。 (2)Connecting a Property Page to an ActiveX Control:简单设置就行 (3)Associating a Property Page with a Property:也是简单设置了。 (4)Using Standard Property Pages:StandardFont, StandardColor, and StandardPicture. 讲了些相关的细节。 (5)Property Page Design Guidelines:一些可以使你的属性页看起来专业的提示。   9、To Read (1)"General Principles of Component Design" (2)"Debugging, Testing, and Deploying Components." (3)"Binding Your Control to a Data Source" 看看这个特性满足要求不 Future Re-read (4)"Programming with Objects”

继续阅读