Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003.

Similar presentations


Presentation on theme: "CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003."— Presentation transcript:

1 CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003

2 ActiveX Background important part of Microsoft's DNA Distributed interNet Applications software components delivered from network where and when needed COM (component object model) makes it possible for individual components to work together

3 ActiveX Includes scripting on client, or on server (ASP) controls – used locally or in web pages ActiveX documents – browser can show Office files: Word, Excel, etc. ADO – provides way to get data server components – interface IIS to other data sources

4 What Are ActiveX Controls? like other VB controls: text box, list box, data control, etc. may be created by third parties, rather than Microsoftthird parties other software companies individual programmers: people like you  you could sell through third party vendorsvendors

5 How Create ActiveX Controls? hook together existing VB controls added code makes them work together modify existing VB controls added code changes their behavior create a user-drawn control VB graphics methods create appearance added code provides desired behavior combinations of above

6 Combining Existing Controls get all existing functionality "inherit" properties and methods handled as a single unit by code users understand it easily based on previous experiences with individual components built into the control

7 Example: Address Control File>New Project>ActiveX Control change project and control names add textboxes and labels not too far apart add appropriate Name properties click and drag corners to size the form sets Height and Width properties

8 Address Control - 2 add some code Resize event – pp. 309-310'Notes With UserControl 'connect it to 'items with dots Property procedure – p. 310'Notes s = s & txtStreet & vbCrLf 'appends string with Cr and Lf 'to previous string

9 Testing Address Control create another project to test it File>Add Project>Standard EXE note new icon on Toolbox close UserControl window may need to use Window menu to close draw this control on the new form test code by resizing the control

10 Testing Address Control - 2 set the standard EXE as startup project right click Project 2 in Project Explorer note boldface on startup project add Command button and code Print UserControl11.AddressText 'might help to check/copy control 'name on Form1 Properties Window run project'Notes

11 Testing in Browser some ActiveX controls designed for use in web pages on Internet inside organizations/Intranets if using on the web, need to test in a browser set the ActiveX Control project (Project1.vbp) as the StartUp, then run

12 Compiling Open ActiveX control project (not group) File>Make [file].ocx save the.ocx file somewhere it will be easy to find e.g., in a new folder among your Visual Studio>Visual Basic files unload control project

13 Testing Compiled Control start a standard EXE add your new ocx to Toolbox with Project> Components> Browse> OK use new icon on toolbox to add to form change StartUp Project to Project 2 (the new Standard EXE) add a button and some code for it run project

14 Enhancing an Existing Control alternative to adding same code for desired behavior in multiple projects build code into a custom control instead can add properties, methods, events to a control's existing functionality e.g., add things to a textbox or button

15 Creating an Enhanced Control File>New Project>ActiveX Control make project name = TextP right click Project 1>Properties>Project Name and change it view Properties Window, change (Name) to something different e.g., TextP1 add textbox to upper left corner of form reduce form width/height to textbox size

16 Adding New Behavior add a resize event to UserControl Private Sub UserControl_Resize() Text1.Height = UserControl.ScaleHeight Text1.Width = UserControl.ScaleWidth End Sub add code for capitalization behavior Private Sub Text1_LostFocus() Text1 = StrConv(Text1, vbProperCase) End Sub'Notes

17 Compiling File>Make [file].ocx save the.ocx file somewhere it will be easy to find e.g., in a new folder among your Visual Studio>Visual Basic files remove ActiveX control project

18 Testing Enhanced Control create a new project to test it File>New Project>Standard EXE add your new ocx to Toolbox with Project> Components> Browse> OK click/drag new control onto form for every input that needs to have first letter capitalized (on all words) add regular textboxes otherwise

19 Testing / Compiling test new form be sure the new Project is the StartUp form if haven't done so already, re-open ActiveX control and compile it for use in other projects save the.ocx file in a new folder e.g., among your Visual Studio>Visual Basic files

20 Control Interface Wizard comes with VB, automates some of code creation for custom controls Add-Ins>Add-In Manager>Visual Component Manager 6.0 needs to say Startup/Loaded on right side  may need to double click it to get it right

21 Control Interface Wizard - 2 File>New Project>ActiveX Control draw textbox on top left corner of form reduce form size to size of textbox delete Text1 from Text property click UserControl set UserControl.Name=txtCharLimit make sure Public=True (usual default)

22 Control Interface Wizard - 3 Project>Add User Control>VB ActiveX Control Interface Wizard, Next select, add (>) Text property, Next New CharAccept (Property) OK New UserError (Event) OK, Next

23 Control Interface Wizard - 4 Set Mapping (Public Name) click Text (on left) (Control) click txtCharLimit (on right) (Member) Text (on right) Next

24 Control Interface Wizard - 5 Set Attributes Public Name = CharAccept Data Type = Integer Default Value = 0 Description = [programmer comments] Next, Finish look at Summary (To Do list)

25 Control Interface Wizard - 6 view code note warnings not to delete comments used by code generator to work with code the next time if don't delete comments, can still use Control Wizard after adding programmer written code to generated code

26 Control Interface Wizard - 7 add Limited.Zip code (pp. 329-330 or www.mcp.com/info ISBN=0789715422) www.mcp.com/info replace code for Let CharAccept add code for txtCharSet_KeyPress in copied code, need to change every mCharAccept to m_CharAccept create standard EXE, add control, run standard EXE needs to be start up object change CharAccept property of control 1, 2

27 THE END following slides have not been completed yet

28 Property Pages Wizard also comes with VB, automates setting properties for custom controls unload previous standard EXE 1 st way to start Project>References>VB Property Page Wizard>OK Project>Add Property Page>VB Property Page Wizard>Open

29 Property Pages Wizard - 2 other way to start Add-Ins>Add-In Manager>VB 6 Property Page Wizard>OK needs to say Loaded: may need to double click to get it right Add-Ins>Property Page Wizard>Next

30 Property Pages Wizard - 3 Add-Ins>ActiveX Property Page Wizard, Next click Add, rename new page as General, OK, Next select CharAccept, Next, Finish

31 Property Pages Wizard - 3 create standard EXE, add this control click on control click Custom in Properties Window click General tab set CharAccept = 1 (or 2) run


Download ppt "CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003."

Similar presentations


Ads by Google