来自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).
![image image](https://p-blog.csdn.net/images/p_blog_csdn_net/slowgrace/469249/o_image_thumb_1_633851693424036250.png)
(2)ActiveX Control、UserControl及其构成控件之间的关系
![image image](https://p-blog.csdn.net/images/p_blog_csdn_net/slowgrace/469249/o_image_thumb_2_633851693433411250.png)
这个帖子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.
![](http://www.dotnetscraps.com/samples/bullets/038.gif)
![](http://www.dotnetscraps.com/samples/bullets/038.gif)
![](http://www.dotnetscraps.com/samples/bullets/038.gif)
![](http://www.dotnetscraps.com/samples/bullets/038.gif)
![](http://www.dotnetscraps.com/samples/bullets/038.gif)
![](http://www.dotnetscraps.com/samples/bullets/038.gif)
ShapeLabel1.Tag = "Triceratops"用的是容器的属性,而ShapeLabel1.Object.Tag = "Triceratops"
用的是控件的属性(其中这个Object其实也是来自Extender的接口)。
![](http://www.dotnetscraps.com/samples/bullets/038.gif)
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.
![](http://www.dotnetscraps.com/samples/bullets/022.gif)
![](http://www.dotnetscraps.com/samples/bullets/022.gif)
![](http://www.dotnetscraps.com/samples/bullets/022.gif)
5、Visual Basic ActiveX Control Features(I just skim through it )
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
![](http://www.dotnetscraps.com/samples/bullets/027.gif)
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