Microsoft KB Archive/185539

= How To Create a Web Aware UserControl =

Article ID: 185539

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q185539



SUMMARY
This article covers the creation of a Web-aware Usercontrol that downloads images from a public site from the Internet.



MORE INFORMATION
This example shows how you can create controls that are Web-aware:

  Start Visual Basic and select the ActiveX Control (this creates a Usercontrol project) in the New Project dialog box. Add a picture control and a label to the Usercontrol project making sure to place the label above the picture control. Add the following code: Option Explicit Const vbAsyncTypePicture = 0

Private Sub UserControl_AsyncReadComplete(AsyncProp As     AsyncProperty) On Error Resume Next Set Picture1.Picture = AsyncProp.Value End Sub

Private Sub UserControl_Initialize 'PLEASE NOTE: 'The URL could be in the form of a shared directory, 'FTP or a HTTP. The convention below, is used as     'an example only. Do not try to use this URL as it is     'in fact bogus. UserControl.AsyncRead _ "http://example.microsoft.com/example.jpg", _ vbAsyncTypePicture End Sub   Add a Caption to the label: Label1.Caption = "Image View"

 Rename the project to something other than Project1 and create the control by compiling to an OCX. Start a new standard exe project and add the new control to it. When you place the control on the form, the image automatically appears.

You could just as easily add a timer to this project, and use it to change the image number. You could also use a public variable that would enable your control to communicate with the form and change the image from outside the control.

