天天看點

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”

繼續閱讀