See Also Example
Transfers the contents of a picture control to the destination application in a dynamic data exchange (DDE) conversation.
The control must be a picture box on a form that is acting as a source in a DDE conversation.
When other applications establish automatic links with a form in your application, Visual Basic notifies them when the contents of text boxes and labels on the form change. However, Visual Basic does not automatically notify DDE destinations when the Picture property of a picture on a source form changes. Because the amount of data in a picture can be very large, and because it seldom makes sense to update destinations as each pixel in the picture changes, Visual Basic requires that you use the LinkSend method to explicitly notify DDE destinations when a picture box has changed.
LinkSend Method Example
The example allows you to draw lines in a picture box and then uses the LinkSend method to update DDE destinations with the new contents of the picture box. Draw lines by clicking the left mouse button; update DDE destinations by clicking the right mouse button. To try this example, place a picture box named Picture1 on a form. Set the LinkMode property for the form to Normal. Paste the code into the Declarations section of the form and start the Visual Basic example running by pressing F5. Once you have the example running, start another application that can accept picture data through DDE, such as Microsoft Excel or Microsoft Word for Windows. Create an automatic link in that other application to the picture control in your application. For example:
Microsoft Excel 3.0create a picture and size it so you can see the data when it is sent. Enter the following formula for the picture into the Excel Formula bar:
Microsoft Word for Windows 2.0insert a field. Enter the following text into the Field Code text box, replacing the equal sign:
ddeauto project1 form1 picture1
Format the field paragraph so that line spacing is automatic.
In both cases, if the Visual Basic project name is not Project1, you should substitute the appropriate project name in the formulas above. Likewise, if the LinkTopic property for the form is not Form1, you should substitute the contents of the LinkTopic property for Form1 in the formula above.
Note You must start the Visual Basic example before you establish the link from the other application.
Sub Picture1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim LeftButton, RightButton ' Declare variables.
Picture1.AutoRedraw = True ' Turn on AutoRedraw.
LeftButton = Button And 1 ' Define left button.
RightButton = Button And 2 ' Define right button.
' Left button draws a line to the point from the previous end point.
' Right button updates DDE destinations with the contents of the picture.
If LeftButton Then
Picture1.Line -(X, Y) ' Draw lines in picture box.
ElseIf RightButton Then ' Update the picture in the
Picture1.LinkSend ' other application.
DoEvents ' Yield to Windows events.