|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
When you embed an object into an OLE control, that control stores the name of the application that supplied the object, along with its data. The OLEType property of the control is set to Embedded (1). When you link an object to an OLE control, that control stores the name of the application that supplied the object and a reference to the data. The OLEType property of the control is set to Linked (0). Note that because an embedded objects data is stored in your program, youre responsible for storing and reading that data if it changes. To do that, well use the SaveToFile and ReadFromFile methods in this chapter. You can also specify the types of objects that an OLE control can take by setting its OLETypeAllowed property to Linked (0), Embedded (1), or Either (2). To embed objects into an OLE control at runtime, you usually use the Insert Object object of the container programs Object menu. To link objects to an OLE control, you usually copy the object in the server application and use the Paste special menu object in the OLE container.
Thats it, then, for the overview of OLE. Weve seen how the process works in overview; now its time to turn to this chapters Immediate Solutions. Immediate SolutionsAdding An OLE Control To A FormThe Testing Department is on the phone again. How about providing all the functionality that Microsoft Excel has in your new program? Um you say. It would be really great, they say, if we could let users work with spreadsheets using all the Excel commands theyre used to. Can you have it done by next week? Using the OLE control, you can embed or link objects from OLE server programs like Excel into your own program. In this way, you can present your programs users with a spreadsheet thats not just like Excelit is Excel. The OLE control is an intrinsic Visual Basic control, and it appears in the toolbox when Visual Basic first starts. The OLE Control tool is the eleventh tool down on the left in the toolbox in Figure 26.3you cant miss it; its the one with the letters OLE in it.
Add an OLE control to a form now by double-clicking the OLE Control tool. When you do, the OLE control appears in the form, and a moment later, the Insert Object dialog box appears, as shown in Figure 26.4.
Now that youve created an OLE control, you can use the Insert Object dialog box to embed or link an OLE object into that control, and well see how that works in the next two topics in this chapter. Creating And Embedding An OLE Object At Design TimeWhen you add an OLE control to a Visual Basic program, the Insert Object dialog box appears, as shown in Figure 26.4, and you can use this dialog box to create and embed a new OLE object in your OLE control. Make sure the Create New option is selected, find the name of the OLE server application you want to use, and click on OK. For example, weve embedded a new Microsoft Excel spreadsheet in the OLE control weve added to a form at design time in Figure 26.5. This spreadsheet is activated for in-place editing by default; to close the object, click the form itself outside the OLE control.
Linking Or Embedding An Existing Document At Design TimeWhen you add an OLE control to a form, the Insert Object dialog box appears in order to allow you to insert an OLE object into the new control. As we saw in the previous topic, you can create a new OLE object with the Insert Object dialog box. However, you can also embed or link to an existing file. To do so, click the Create From File option button in the Insert Object dialog box. When you select a file by typing its path and name into the File text box or by using the Browse button, and then click on OK, that file is embedded as an OLE object in the OLE control. Embedding an existing file this way is handy if youve already got a file you want to display and work with in your program, and it saves you the time of creating the file over again from scratch in a new OLE object. You can also link an OLE object to an OLE control using the Insert Object dialog box. To do that, click the box labeled Link In The Insert Object Dialog, then select the file as we did before to embed an object. Autosizing An OLE ControlAfter youve added an OLE control to a form, you can specify how you want that control to handle OLE object insertions: for example, should the control resize itself when an OLE object is inserted in it or not? You can specify how the control should handle object insertions with the SizeMode property. Here are the possible values for the SizeMode property:
Determining How An Object Is Displayed In An OLE Container ControlThere are two ways of displaying an OLE object in an OLE control: displaying that objects content and displaying it as an icon. Throughout this chapter, well use the content display, which is the default, but you can also display it in icon form using the OLE controls DisplayType property. Here are the possible settings for DisplayType:
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |