Chapter 34. Using the Clipboard
Earlier lessons have explained how your program interacts with the user (through controls), the file system, and most recently the printer. This lesson explains how your program can interact with other programs via the clipboard.
In this lesson, you learn how to place text, image, and other data on the clipboard so you can paste it into other applications. You also learn how to receive data pasted into your program from the clipboard.
ADDING DATA TO THE CLIPBOARD
Adding data to the clipboard is fairly easy. The
Clipboard class provides several static methods to place certain kinds of data on the clipboard. Table 34-1 summarizes those methods.
Table 34.1. TABLE 34-1
Copies an audio stream to the clipboard
Copies a list of files to the clipboard as if the user had selected them in Windows Explorer and pressed [Ctrl]+C
Copies an image to the clipboard
Copies a string to the clipboard
Example program AddToClipboard, shown in Figure 34-1 and included as part of this lesson's code download, demonstrates these methods. Use the Copy buttons to copy the corresponding content on the left to the clipboard. (When the program starts, it copies the names of the files in its startup directory into the list box. The bottom image represents an audio file.)
Figure 34.1. FIGURE 34-1
The program uses the following code to copy data ...