重拾VB619:Using a Component's Visual Interface

来自MSDN-2001-OCT: Visual Tools and Languages/Visual Studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/Programmer’s Guide/Part 2: What Can You Do With Visual Basic/Programming With Components/

1. Using a Component's Visual Interface

(1) If a component supports object linking and embedding (OLE),you can link or embed an object into your application without writing any code by using the component's visual interface. You can use a component's visual interface in one of two ways:

a) By adding an OLE container control to your application,then inserting an object into the control.

b) By adding the object's class to the Toolbox,then adding an object of that class to your application just as you would add a control to a form.

(2) An OLE container control can contain only one object at a time. There are several ways to create a linked or embedded object in the OLE container control

2. Contrasting Linked and Embedded Objects

(1) The primary difference between a linked and embedded object is where their data is stored. For example,data associated with a linked object is managed by the application that created it and stored outside an OLE container control. Data associated with an embedded object is contained in an OLE container control and can be saved with your Visual Basic application.

(2) When a linked or embedded object is created,it contains the name of the application that supplied the object,its data (or,in the case of a linked object,a reference to the data),and an image of the data.

(3) Linked Objects: For example,in Figure 10.8,Visual Basic contains a link to the Graph application. Microsoft Word also contains a link to the graph. If the graph's data is changed by either application,the modified graph will appear in both the Visual Basic application and the Microsoft Word document.

(4) With an embedded object,all the data associated with the object is copied to and contained in the OLE container control. Embedded objects can greatly increase file size.

3. Inserting Objects at Design Time with the OLE Container Control

(1) Each time you draw an OLE container control on a form,Visual Basic displays the Insert Object dialog box.

(2) When you insert an object into the OLE container control at design time,the Class,SourceDoc,and SourceItem properties are automatically set for you.

(3) To insert a linked object using the Insert Object dialog box,Select the Create from File option button.

(4) When you use a linked object,every user who runs your application must have access (a valid path) to the linked file and a copy of the application that created the file. Otherwise,when your application is run,an image of the original data is displayed,but the user will not be able to modify the data,nor will the user see changes others may have made to the linked data. This may be a concern if your application is running on a network.

(5)If your application contains a linked object,it is possible for that object's data to be changed by another application when your application is not running. The next time your application is run,changes to the source file do not automatically appear in the OLE container control. To display the current data in the OLE container control,use the control's Update method.

(6)If a user wants to save changes to a linked object,the user must save it from the ActiveX component's menu. The OLE container control's SaveToFile method applies only to embedded objects.

(7)Unlike the data in a linked object,data in an embedded object is not persistent. In other words,if you want changes entered by the user to appear the next time your application is run,you must use the SaveToFile method to save the data.

(8)Creating Objects Using the Paste Special Dialog Box:

In Visual Basic,click the OLE container control with the right mouse button,and choose the Paste Special command from the pop-up menu.

4. Creating Objects at Run Time with the OLE Container Control

(1) By using the OLE container control's Object property,you can also use the properties and methods of the linked or embedded object. The Object property is a run-time,read-only property that holds a reference to the object in an OLE container control.

(2) You can create a linked object from a file at run time with the OLE container control's CreateLink method.

(3) To create an embedded object from a file at run time,you can use the CreateEmbed method.

(4) the following code fragment creates an empty embedded object and then activates the application that created it using the default DoVerb action.

oleObj1 . CreateEmbed "" , "Excel.Sheet"
oleObj1 . DoVerb - 5 ' Activate

With the DoVerb method,the user can enter any data into the application at run time. The user can then show this newly entered data in the OLE container control by choosing the ActiveX component's Update command (this menu command should appear on the component's File menu).

(5) Binding a Database to the OLE Container Control: To bind data to one of these databases,specify the source of data (recordset name) in the DataSource property and the field name from that data source in the DataField property of the OLE container control. When displaying an object from a database,the OLE container control allows the user to activate,edit,and update the object. As with any bound control,the updated object is automatically written back to the database when the record position is changed.

5. Letting the User Specify Objects at Run Time

You use the OLE container control's InsertObjDlg method to display the Insert Object dialog box,or you can use the PasteSpecialDlg method to display the Paste Special dialog.

Private Sub cmdInsert_Click ()
' Display Insert Object dialog box.
oleObj1 . InsertObjDlg
' Check to make sure object was created with the
' OLEType property.
If oleObj1 . OLEType = vbOLENone Then
MsgBox "Object Not Created."
End If
End Sub

Private Sub oleObj1_Click ()
' Determine if the data contained on the Clipboard
' can be pasted into the OLE container control.
If oleObj1 . PasteOK Then
' Display Paste Special dialog box.
oleObj1 . PasteSpecialDlg
' Check to make sure object was created.
If oleObj1 . OLEType = vbOLENone Then
MsgBox "Object Not Created."
End If
End If
End Sub

6. Determining How an Object is Displayed in the OLE Container Control

(1) You can use the OLE container control's DisplayType property to indicate if the object will appear as an icon (set DisplayType = 1),or if the object's data will be displayed in the control (set DisplayType = 0).

(2) You use the SizeMode property to determine how an object's icon or data image is displayed in the OLE container control when the control is not UI (user-interface) active.

7. Activating an Object in the OLE Container Control

(1) While the OLE container control's DoVerb method activates an object at run time,you can use the AppIsRunning property to determine whether the application supplying the object is activated and running. You can set AppIsRunning to True to start the ActiveX component,which causes objects to activate more quickly. You can also set this property to False to close the application or take another appropriate action when the object loses focus.

(2) Some embedded objects can be edited (activated) from within the OLE container control. This is called in-place activation,because users can double-click an object in your application and interact with application supplying the object,without switching to a different application or window.

(3) For objects that support in-place activation,you can set the AutoActivate property so that users can activate an object at any time.

(4) If you want to display the ActiveX component's menus at run time when the user clicks the OLE container control,you must define at least one menu item for the form and set its Visible property to False.

8. Responding to Moving or Sizing the Container

An ObjectMove event occurs when the user moves or resizes the object contained in the OLE container control.

Private Sub oleObj1_ObjectMove( Left As Single , Top As _
Single , Width As Single , Height As Single)
' This method resizes the OLE container control to
' the new object size.
oleObj1 . Move oleObj1 . Left , oleObj1 . Top , _
Width , Height
' This method moves the OLE container control
' to the new object position.
oleObj1 . Move Left , Top , _
oleObj1 . Width , oleObj1 . Height
' Repaints the form.
Me . Refresh
End Sub

9. Saving and Retrieving Embedded Data

(1) Data associated with an embedded object is not persistent; To save updated data from an object to a file,you use the OLE container control's SaveToFile method. Objects in the OLE container control can be saved only to open,binary files.

Private Sub cmdSaveObject_Click ()
Dim FileNum as Integer
' Get file number.
FileNum = FreeFile
' Open file to be saved.
Open "TEST.OLE" For Binary As # FileNum
' Save the file.
oleObj1 . SaveToFile FileNum
' Close the file.
Close # FileNum
End Sub

(2) When you use the SaveToFile or ReadFromFile methods,the file position is located immediately following the object. Therefore,if you save multiple objects to a file,you should read them in the same order you write them.

Private Sub cmdOpenObject_Click ()
Dim FileNum as Integer
' Get file number.
FileNum = FreeFile
' Open the file.
Open "TEST.OLE" For Binary As # FileNum
' Read the file.
oleObj1 . ReadFromFile FileNum
' Close the binary file.
Close # FileNum
End Sub

(3) The Updated event is invoked each time the contents of an object is changed. This event is useful for determining if an object's data has been changed because it was last saved. To do this,set a global variable in the Updated event indicating the object needs to be saved. When you save the object,reset the variable.

(4) If a user wants to save changes to a linked file,the user must choose the Save command from the ActiveX component's File menu because the SaveToFilemethod applies only to embedded objects.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 -------------------------------- 数字类型的格式化 --------------------------------     固定格式参数:     General Number 普通数字,如可以用来去掉千位分隔号     format$("100,1
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和系统设置的区域语言的日期和时间格式相关。意思是尽管你用诸如 Format(Now, "MM/dd/yyyy"),如果系统的设置格式区域语言的日期和时间格式分隔符是"-",那他还会显示为 MM-dd-yyyy     只有拼凑: <%response.write
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接添加本ApplicationEvents.vb 到工程即可 ‘添加后还需要一个From用来显示错误。如果到这步还不会则需要先打好基础啦 ‘======================================================== ‘以下事件
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没有认真去找这个方法呀。 https://blog.csdn.net/chzjxgd/article/details/6176325 金蝶K3 BOS的插件官方是用VB6编写的,如果  能用.Net下的语言工具开发BOS插件是一件很愉快的事情,其中缘由不言而喻,而本文则是个人首创,实现在了用V
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, tmpStr As String, s As String Dim x As Integer, y As Integer, subStr As String If MsgBox("确定要分列处理吗?请确定分列的数据会覆盖它后面的单元格!", _
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) 2 Dim path As String, hash As String 3 For Each fil
  Imports MySql.Data.MySqlClient Public Class Form1 ‘ GLOBAL DECLARATIONS Dim conString As String = "Server=localhost;Database=net2;Uid=root;Pwd=123456;" Dim con As New MySqlConnection
‘導入命名空間 Imports ADODB Imports Microsoft.Office.Interop   Private Sub A1() Dim Sql As String Dim Cnn As New ADODB.Connection Dim Rs As New ADODB.Recordset Dim S As String   S = "Provider=OraOLEDB.Oracl
Imports System.IO Imports System.Threading Imports System.Diagnostics Public Class Form1 Dim A(254) As String    Function ping(ByVal IP As Integer) As String Dim IPAddress As String IPAddress = "10.0.
VB运行EXE程序,并等待其运行结束 参考:https://blog.csdn.net/useway/article/details/5494084 Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Pr
今天碰到一个问题,登陆的时候,如果不需要验证手机号为空,则不去验证手机号 因为登陆的时候所有的验证信息都存放在一个数组里 Dim CheckUserInfo() As String ={UserBirthday, SecEmail, UserMob, UserSex, RealNameFirst, RealName, CheckCardID, CheckCardType, Contactemail
在VB6.0中,数据访问接口有三种: 1、ActiveX数据对象(ADO) 2、远程数据对象(RDO) 3、数据访问对象(DAO) 1.使用ADO(ActiveX Data Objec,ActiveX数据对象)连接SQL Server 1)使用ADO控件连接 使用ADO控件的ConnectionString属性就可以连接SQL Server,该属性包含一个由分号分隔的argument=value语
注:大家如果没有VB6.0的安装文件,可自行百度一下下载,一般文件大小在200M左右的均为完整版的软件,可以使用。   特别提示:安装此软件的时候最好退出360杀毒软件(包括360安全卫士,电脑管家等,如果电脑上有这些软件的话),因为现如今的360杀毒软件直接会对VB6.0软件误报,这样的话就可能会在安装过程中被误报阻止而导致安装失败,或者是安装后缺乏很多必须的组件(其它的杀毒软件或安全卫士之类的
Private Sub Form_Load() Call conndb End Sub Private Function conndb() Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim strCn, sql As String Dim db_host As String Dim db_user As String
  PPSM06S70:  Add  moddate  EDITSPRINTJOB:  MAX(TO_CHAR(ETRN.MODDATE, ‘yyyy/mm/dd/HH24:MI AM‘)) ACTUAL_SHIPDATE   4.Test Scenario (1) :Query SQL Test DN:8016578337 SELECT CTRN.TKCTID TRUCK_ID,        
  沒有出現CrystalReportViewer時,須安裝CRforVS_13_0. 新增1個數據集,新增1個數據表,添加二列,列名要和資料庫名一樣. 修改目標Framework 修改app.config, <startup >改成<startup useLegacyV2RuntimeActivationPolicy ="true">  CrystalReport1.rpt增加數據庫專家 在表單
Imports System.Threading Imports System Public Class Form1 Dim th1, th2 As Thread Public Sub Method1() Dim i As Integer For i = 1 To 100 If Me.Label1.BackColor =
Friend Const PROCESS_ALL_ACCESS = &H1F0FFF = 2035711 Friend Const PROCESS_VM_READ = &H10 Friend Const PROCESS_VM_WRITE = &H20 Friend Const PAGE_READONLY = &H2 Friend Const PAGE_READWRITE = &H4 Friend
以下代码随手写的 并没有大量测试 效率也有待提升 如果需要C#的请自行转换 Function SplitBytes(Data As Byte(), Delimiter As Byte()) As List(Of Byte()) Dim i = 0 Dim List As New List(Of Byte()) Dim bytes As New
Imports System.Data.SqlClient Public Class Form1 REM Public conn1 As SqlConnection = New SqlConnection("server=.; Integrated Security=False;Initial Catalog= mydatabase1; User ID= sa;password")