来自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
This section of MSDN discussess in more depth on every aspects of the authoring of ActiveX Controls.
1、ActiveX Control和UserControl
(1)The .ctl and .ctx files completely define an ActiveX control's appearance and interface (properties, methods, and events).
(2)ActiveX Control、UserControl及其构成控件之间的关系
这个帖子19楼及以下有一些有价值的关于这个话题的讨论。
2、UserControl的关键事件
(1)The key events in the life cycle of a UserControl are
Initialize, InitProperties, ReadProperties, Resize, Paint, WriteProperties, and Terminate. 有时还会有Show and Hide Events。
(2)如果你的控件是由其他空间“搭成”的,那你重点关注Resize;如果你的控件是自己手画的,那你重点关注Paint。
(3)在“Understanding Control Lifetime and Key Events”一节,详细叙述了几种典型的Scenarios里各种事件发生的顺序和细节。
(4)在Initialize事件里,Extender和AmbientProperties对象都还不可用,要到InitProperties或ReadProperties事件里才可用。
(5)
The run-time instance never gets a chance to save property settings. Changes to property values while the program was running are discarded.
设计时的实例则可以在WriteProperties事件里
save its property values to the
in-memory copy of the .frm filei.
(6)如果你打开工程,并且打开含UserControl的窗体,那么你不仅会得到ReadProperties事件还会得到WriteProperties,因为UserControl会向内存里的窗体实例写入属性值。
(7)Events Peculiar to UserControls:
GotFocus and
LostFocus events,
AccessKeyPress event,
AmbientChanged event。
3、Extender
Container objects supply additional properties, methods, and events that appear to the user to be part of your control.
A UserControl object can access extender properties through its Extender object.
References to Extender properties will always be
late bound.
ActiveX规范规定了控件容器应该实现的属性,但是控件容器未必都实现了,所以使用这些属性的时候应该始终用错误捕获机制。
Extender properties are provided
for the developer who uses your control.
Container objects supply additional properties, methods, and events that appear to the user to be part of your control.
A UserControl object can access extender properties through its Extender object.
References to Extender properties will always be
late bound.
ActiveX规范规定了控件容器应该实现的属性,但是控件容器未必都实现了,所以使用这些属性的时候应该始终用错误捕获机制。
Extender properties are provided
for the developer who uses your control.
If an instance of your control is placed on a container that has an extender property with the same name as a property of your control, the user will see the extender property. 比如你的控件和控件容器都有tag这个属性,那么
ShapeLabel1.Tag = "Triceratops"用的是容器的属性,而ShapeLabel1.Object.Tag = "Triceratops" 用的是控件的属性(其中这个Object其实也是来自Extender的接口)。
一些常用的Extender属性:
Name, Visible, Parent, Cancel, Default, Left, Top, Width, Height
4、AmbientProperties
You can also obtain information about the container through
the UserControl object's Ambient property. The Ambient property of the UserControl object returns a reference to the AmbientProperties object.
由于container-specific ambient properties不在Type Library里描述,所以它们是后期绑定的,而且使用的时候要始终用错误捕获机制。
Important Ambient Properties:
UserMode, LocaleID, DisplayName, ForeColor, BackColor, Font, and TextAlign, DisplayAsDefault, The AmbientChanged Event.
You can also obtain information about the container through
the UserControl object's Ambient property. The Ambient property of the UserControl object returns a reference to the AmbientProperties object.
由于container-specific ambient properties不在Type Library里描述,所以它们是后期绑定的,而且使用的时候要始终用错误捕获机制。
Important Ambient Properties:
UserMode, LocaleID, DisplayName, ForeColor, BackColor, Font, and TextAlign, DisplayAsDefault, The AmbientChanged Event.
5、Visual Basic ActiveX Control Features(I just skim through it )
关于
焦点的处理:CanGetFocus, GotFocus and LostFocus events, EnterFocus and ExitFocus events, provide a visual indication that your control has the focus, Receiving Focus via Access Keys, Forwarding Focus to the Next Control in the Tab Order, Validate event and CausesValidation.
可以放在UserControl上的Controls:所有控件除了这OLE容器,另外可插入对象(比如Microsoft Excel Charts)也不行。另外这一节还讨论了关于控件
licenses的一些问题。
Object Models for Controls:ActiveX Controls只能有
Dependent Ojbects,这种对象不能用new来生成。
Allowing Developers to Put Controls on Your Control:
ControlContainer property,ContainedControls collection(注意它和Controls Collection不同),Clipping for the contained controls, an ISimpleFrame-aware container must implement the IVBGetControls interface.
Allowing Your Control to be
Enabled and Disabled: some subtle details about the enabled property, 最基本的原则是由container来决定一个control是否Enabled。
Adding a
Font Object to Your User Control:有完整的步骤。
Giving Your Control a
Transparent Background:几种方法和性能考虑。
Creating Lightweight Controls:
windowless controls (没句柄,hWnd返回的是容器的句柄)。要做成透明的话,要处理HitTest事件,要了解一个控件的几个相关区域,并要考虑由HitTest带来的性能问题(ClipBehavior and HitBehavior properties)。
Allowing Developers to Set
Access Keys for Your Control: 一些细节的考虑(构成控件的快捷键)。
Making Your Control
Align to the Edges of Forms:Alignable property.
Making Your Control
Invisible at Run Time: InvisibleAtRuntime
Adding an
AboutBox to Your Control
Providing
a Toolbox Bitmap for Your Control
Allowing Your Control to be a
Default or
Cancel Button
Adding
Internet Features to Controls几乎没看
Designing Controls for Use With
HTML没看
Binding a Control to a Data Source:
Allowing Developers to Edit Your Control at Design Time:
EditAtDesignTime(没太看懂,大致是说可以在设计时也像在运行时一样)
6、Drawing Your Control
(1)User-Drawn Controls
When you're doing your own drawing, the only place you need to put drawing code is in the UserControl_Paint event procedure.
这一小节有个比较完整的例子讲如何处理自画控件的外表。
(2)Providing Appearance Using Constituent Controls
在这个事件UserControl_Resize里处理。这一小节也讨论了若干细节。
7、To Read
(1)"General Principles of Component Design"
(2)"Debugging, Testing, and Deploying Components."可以给UserControl加事件,与给类加事件一样简单。
(3)"Building ActiveX Controls"
(4)"Creating Property Pages for ActiveX Controls."
(5)"Binding Your Control to a Data Source" 看看这个特性满足要求不
So sorry that I overwrote the 1st part of this note
本文深入探讨了ActiveX控件和用户控件(UserControl)的设计与实现过程,包括关键事件如Initialize、Paint等的使用场景,Extender和Ambient属性的作用及应用场景,以及自绘控件和构成控件的绘制技巧。
4123

被折叠的 条评论
为什么被折叠?



