DataFormats.GetFormat 方法

定義

傳回有 Windows 剪貼簿數字 ID 和名稱的 DataFormats.Format

多載

GetFormat(Int32)

傳回有 Windows 剪貼簿的數字 ID 和指定 ID 名稱的 DataFormats.Format

GetFormat(String)

傳回指定格式的 Windows 剪貼簿數字 ID 和名稱的 DataFormats.Format

GetFormat(Int32)

傳回有 Windows 剪貼簿的數字 ID 和指定 ID 名稱的 DataFormats.Format

public:
 static System::Windows::Forms::DataFormats::Format ^ GetFormat(int id);
public static System.Windows.Forms.DataFormats.Format GetFormat (int id);
static member GetFormat : int -> System.Windows.Forms.DataFormats.Format
Public Shared Function GetFormat (id As Integer) As DataFormats.Format

參數

id
Int32

格式 ID。

傳回

有 Windows 剪貼簿的數字 ID 和格式名稱的 DataFormats.Format

範例

下列程式碼範例示範此成員的使用。

using namespace System;
using namespace System::Windows::Forms;
int main()
{
   
   // Create a DataFormats::Format for the Unicode data format.
   DataFormats::Format^ myFormat = DataFormats::GetFormat( 13 );
   
   // Display the contents of myFormat.
   Console::WriteLine( "The Format Name corresponding to the ID {0} is :", myFormat->Id );
   Console::WriteLine( myFormat->Name );
}
using System;
using System.Windows.Forms;

   public class DataFormat_GetFormat
   {
      static void Main()
      {

         // Create a DataFormats.Format for the Unicode data format.
         DataFormats.Format myFormat = DataFormats.GetFormat(13);

         // Display the contents of myFormat.
         Console.WriteLine("The Format Name corresponding to the ID "+myFormat.Id+" is :");
         Console.WriteLine(myFormat.Name);
      }
   }
Imports System.Windows.Forms

Public Class DataFormat_GetFormat
   
   Shared Sub Main()
      
     ' Create a DataFormats.Format for the Unicode data format.

      Dim myFormat As DataFormats.Format = DataFormats.GetFormat(13)

      ' Display the contents of myFormat.

      Console.WriteLine(("The Format Name corresponding to the ID " + myFormat.Id.ToString + " is :"))
      Console.WriteLine(myFormat.Name)

   End Sub

End Class

備註

此成員通常用於註冊原生剪貼簿格式。

GetFormat當您想要擷取 DataFormats.Format 包含識別碼/格式名稱組的實例時,請使用識別碼號碼呼叫 。 一般而言,識別碼名稱和號碼是由您使用 Clipboard 來介面的應用程式建立者所發佈。 例如,Visual Basic 中動態資料 Exchange (DDE) 交談資訊的識別碼為 &HBF00 ,格式名稱為 vbCFLink

使用任何唯一識別碼來呼叫這個方法,將識別碼/格式名稱組新增至 static 類別中 DataFormats 格式名稱/識別碼組的清單。 新的名稱會藉由串連 「格式」和識別碼來建立。 此配對未註冊為新 Clipboard 格式,因為您尚未提供名稱。

另請參閱

適用於

GetFormat(String)

傳回指定格式的 Windows 剪貼簿數字 ID 和名稱的 DataFormats.Format

public:
 static System::Windows::Forms::DataFormats::Format ^ GetFormat(System::String ^ format);
public static System.Windows.Forms.DataFormats.Format GetFormat (string format);
static member GetFormat : string -> System.Windows.Forms.DataFormats.Format
Public Shared Function GetFormat (format As String) As DataFormats.Format

參數

format
String

格式名稱。

傳回

有 Windows 剪貼簿的數字 ID 和格式名稱的 DataFormats.Format

例外狀況

.NET 5 和更新版本: formatnullEmpty 或空白字元。

新的 Clipboard 格式登錄失敗。

範例

下列程式碼範例示範如何擷取 DataFormats.Format 代表格式名稱/識別碼組的 。 要求 UnicodeText 格式,而且所擷 DataFormats.Format 取的內容會顯示在文字方塊中。

此程式 textBox1 代碼需要具現化。

private:
   void GetMyFormatInfomation()
   {
      // Creates a DataFormats.Format for the Unicode data format.
      DataFormats::Format^ myFormat = DataFormats::GetFormat(
         DataFormats::UnicodeText );
      
      // Displays the contents of myFormat.
      textBox1->Text = String::Format( "ID value: {0}\nFormat name: {1}",
         myFormat->Id, myFormat->Name );
   }
private void GetMyFormatInfomation() {
   // Creates a DataFormats.Format for the Unicode data format.
   DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.UnicodeText);

   // Displays the contents of myFormat.
   textBox1.Text = "ID value: " + myFormat.Id + '\n' +
      "Format name: " + myFormat.Name;
}
Private Sub GetMyFormatInfomation()
    ' Creates a DataFormats.Format for the Unicode data format.
    Dim myFormat As DataFormats.Format = _
       DataFormats.GetFormat(DataFormats.UnicodeText)
       
    ' Displays the contents of myFormat.
    textBox1.Text = "ID value: " + myFormat.Id.ToString() + ControlChars.Cr _
                  + "Format name: " + myFormat.Name
End Sub

備註

當您需要現有格式的 Windows 剪貼簿數值識別碼時,請使用格式名稱呼叫 GetFormat

使用您自己的格式名稱呼叫這個方法,以建立新的 Clipboard 格式類型。 如果指定的格式不存在,這個方法會將名稱註冊為 Windows 登錄的剪貼簿格式,並取得唯一的格式識別碼。 這個新的名稱/識別碼組將會新增至 static 類別中 DataFormats 格式名稱/識別碼組的清單。

另請參閱

適用於