The System ObjectsUnlike the objects you declare, system objects are the Printer and App objects you've already used in this book. Although you can't pass system objects (they're already global in nature), you can treat them much like the objects you create. System objects represent specific elements of your application. Table 16.1 describes the system objects and lists some important methods you can apply to them. Table 16.1. System objects support several methods.
You've worked with most of the system objects - especially the Printer and Screen objects - before today's lesson. The App object is useful for determining runtime information about the program path and filename, and the Clipboard object provides some interesting functionality you may want to use. Also, the Debug object lets you interact with your program during testing to help get the bugs out. Depending on your application's needs, the Clipboard object is relatively simple to program. The Clipboard object is the same Clipboard Windows uses; therefore, your application can copy or cut information to the Clipboard object, and users can paste that information in another Windows application. Also, your application can paste information that's contained in the Windows Clipboard into the Clipboard object. You can use the Clipboard object and its properties to select text from within your program and to determine the text selected by users. For example, the SelStart property marks the starting position of the selection cursor in the text box (or whatever control receives the selection). A value of 0 for SelStart places the cursor before the first character. SelLength determines how many characters are selected for Clipboard work. If you select text by setting SelStart and SelLength values, that text goes to the Clipboard object when a user presses Ctrl+C (copy) or Ctrl+X (cut). SelText is a string that contains the selected text you've bounded with SelStart and SelLength. If you've selected text in a text box control (or you've asked a user to select text), that text appears in the SelText string value. You can clear the Clipboard object of its current value (the Clipboard object can hold only one value at a time) and send the selected text to the Clipboard with the following code: Clipboard.Clear ' Erase current Clipboard Clipboard.SetText txtName.SelText ' Copy text If you want to copy the Clipboard text into a variable, you can use GetText(), like this: strInfo = Clipboard.GetText() If you want to replace selected text in a control with the text in the Clipboard object, you can do so this way: txtName.SelText = Clipboard.GetText() The GetText() method sometimes uses arguments, and it requires parentheses even if you specify no arguments. For text-based Clipboard work, you don't need to supply any arguments. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
|||