Sie sind auf Seite 1von 2

A c t i ve X c on t ro l s ar e t he de sc en da n t s o f th e f i r s t O CX co nt r o l s t ha t ap pe a re d

w he n V i su a l
B a s ic 4 w a s r e le a se d . W h i l e t he y r e ta i n t h e sa me f i l e ex t en s i on , th ey ' r e v er y
d i f f e re n t
beneath the surface. The original OCX controls included a lot of low level -

functionality
(and consequently had to support many COM interfaces), and therefore were
heavy and

relatively slow. The new ActiveX controls were specifically redesigned to be


embedded in
HTML pages and delegate much of their functionality to their container, be it
Microsoft
Internet Explorer, a Visual Basic form, or any other ActiveX compliant -

environment. Thanks
to this different approach, ActiveX controls are generally slimmer than old OCXs,
download
faster, and load in memory more rapidly.

ActiveX Fundamentals
A c t i v e X C o n t r o l F u n d a m e n t a l s

V i s ua l Ba s i c 5 an d 6 g i ve y ou a l l t h e to o l s y ou ne ed t o c re a t e p ow er f u l A c t i ve X
c on t r o l s ,
w h ic h y ou ca n th e n re u se in a l l yo ur p ro j e c t s . M o r e pr e c i se l y , y ou c an c re a te t wo
d i f f e re n t
types of ActiveX controls:
q

Pr i v a t e Ac t i v e X co n t ro l s t h a t c an be i n c lu de d i n an y ty p e of V is ua l Ba s i c p ro j e c t .
T h ey ' r e sa ve d i n f i l e s w i t h t he
. ctl
e x te ns i o n , a nd yo u ca n re u se t h em in a ny o th e r V i s ua l Ba s i c p ro j ec t me r e ly by
a dd i ng t h e f i l e t o t he p ro j e c t . ( T h i s
i s re us e a t t h e so u rc e co de l ev e l . )
q
-

Public ActiveX controls that can be included only in ActiveX control projects; you
have to compile them into OCX files, and then you can use them in any other
Microsoft Windows application written in Visual Basic, Microsoft Visual C+ + , or
any other development environment that supports ActiveX controls. (This is reuse at
the binary level.)

V i s ua l Ba s i c 5 wa s t h e f i r s t l an gu a ge t h a t p er m i t t ed pr og r am m e rs to cr ea t e
A c t i ve X c on t ro l s us i ng a v i su a l a pp ro a ch . As yo u' l l se e i n a mo me n t , y ou c an
c re a t e p ow er f u l c on t r o l s by s i mp l y g ro up i ng s im p l e r co n t ro l s t og e t he r : Th e se
c on t r o l s a r e k n o w n a s constituent controls .

By putting together a PictureBox and


two scroll bar controls, for example, you can create an ActiveX control that can
scroll its contents. Visual Basic also allows you to create an ActiveX control
without using any constituent controls. These are the so calledo w n e r d r a w n - -

ActiveX controls.

You should also keep this in mind when working with ActiveX controls: You're
used to distinguishing between two
distinct types of people interacting with your program the developer and the -

user. To better understand how ActiveX


controls behave, you need to take another role into account, the a u t h o r of the
control itself. The author's job is to
prepare a control that will be used by the developer to deliver an application to
the user. As you'll see, the author's and
developer's perspectives are sometimes different, even though the two roles
might be occupied by the same person.
(That is, you might act as the author of the control and then as the developer
who uses it.)

A dd a n ew A c t i ve X c on t r o l pr o j ec t to th e e nv i ro n me n t . T h i s n ew p ro j e c t a l re a dy
i n c lu de s a U se r C on t r o l mo du le .
( A l t e r na t i v e ly , ma nu a l ly ad d a U s e r Co n t ro l mo du l e f ro m t he P r o je c t m en u i f
y ou ' re cr ea t i n g a P r i va t e A c t i ve X
control.)
2 . G iv e t he pr o je c t a m ea n in g fu l na me a nd a de sc r i p t i on . T he f o r me r b ec om e s t he
n am e of th e c on t ro l ' s l ib r a ry , an d t h e l a t te r i s t he s t r i n g t ha t ap pe ar s i n t h e
C om po n en t s d i a lo g bo x fo r a l l th e p ro j ec t s th a t u se th i s c on t r o l . I n t h i s e x a m p l e ,
w e ' l l u s e t h e p r o j e c t ' s n a m e S u p e r TB a n d t h e d e s c r i p t i o n An enhanced TextBox
control .

3. Click on the UserControl designer's window to give it the focus, and then
enter a value for the N a m e property of
t h e c o n t r o l i n t h e P r o p e r t i e s w i n d o w . I n t h i s e x a m p l e , y o u c a n e n t e r Su p e r Te x
t Bo x .

4. Place one or more constituent controls on the surface of the UserControl


designer. In this example, you need to
a dd a L ab e l c on t ro l an d a Te x t Bo x c on t ro l , a s sh ow n i n F i g u re 17 1 -

Das könnte Ihnen auch gefallen