共用方式為


My.Computer.Clipboard.SetText Method 

Writes text to the Clipboard.

' Usage
My.Computer.Clipboard.SetText(text)
My.Computer.Clipboard.SetText(text ,format)
' Declaration
Public Sub SetText( _
   ByVal text As String _
)
' -or-
Public Sub SetText( _
   ByVal text As String, _
   ByVal format As System.Windows.Forms.TextDataFormat _
)

Parameters

  • text
    String. Text to be written. Required.

Exceptions

The following conditions may cause an exception:

Remarks

Possible formats are CommaSeparatedValue, Html, Rtf and UnicodeText.

The method requires AllClipboard.

Previous Clipboard formats are not preserved.

Security noteSecurity Note

Because the Clipboard can be accessed by other users, do not use it to store sensitive information, such as passwords or confidential data.

Tasks

The following table lists examples of tasks involving the My.Computer.Clipboard.SetText method.

To See

Write text to the Clipboard

How to: Write to the Clipboard in Visual Basic

Example

This example writes the string This is a test string. to the Clipboard.

My.Computer.Clipboard.SetText("This is a test string.")

Requirements

Namespace: Microsoft.VisualBasic.MyServices

Class: ClipboardProxy (provides access to Clipboard)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

No

Windows Service

Yes

Web Site

No

Permissions

No permissions are required.

See Also

Reference

My.Computer.Clipboard Object
My.Computer.Clipboard.ContainsText Method
My.Computer.Clipboard.GetText Method
System.Windows.Forms.TextDataFormat
System.Windows.Forms.Clipboard.SetText

Other Resources

Storing Data to and Reading From the Clipboard