Επεξεργασία

Κοινή χρήση μέσω


DataFormats.GetFormat Method

Definition

Returns a DataFormats.Format with the Windows Clipboard numeric ID and name.

Overloads

GetFormat(Int32)

Returns a DataFormats.Format with the Windows Clipboard numeric ID and name for the specified ID.

GetFormat(String)

Returns a DataFormats.Format with the Windows Clipboard numeric ID and name for the specified format.

GetFormat(Int32)

Returns a DataFormats.Format with the Windows Clipboard numeric ID and name for the specified ID.

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

Parameters

id
Int32

The format ID.

Returns

A DataFormats.Format that has the Windows Clipboard numeric ID and the name of the format.

Examples

The following code example demonstrates the use of this member.

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

Remarks

This member is typically used to register native Clipboard formats.

Call GetFormat with an ID number when you want to retrieve a DataFormats.Format instance that contains the ID/format name pair. Typically, the ID name and number is published by the creator of the application that you are using the Clipboard to interface with. For example, the ID number for Dynamic Data Exchange (DDE) conversation information in Visual Basic is &HBF00, and the format name is vbCFLink.

Call this method with any unique ID number to add the ID/format name pair to the static list of format name/ID pairs in the DataFormats class. The new name will be created by concatenating "Format" and the ID number. This pair is not registered as a new Clipboard format because you have not provided a name.

See also

Applies to

GetFormat(String)

Returns a DataFormats.Format with the Windows Clipboard numeric ID and name for the specified 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

Parameters

format
String

The format name.

Returns

A DataFormats.Format that has the Windows Clipboard numeric ID and the name of the format.

Exceptions

.NET 5 and later versions: format is null, Empty, or white space.

Registering a new Clipboard format failed.

Examples

The following code example shows how to retrieve a DataFormats.Format representing a format name/ID pair. The UnicodeText format is requested, and the contents of the retrieved DataFormats.Format are displayed in a text box.

This code requires textBox1 has been instantiated.

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

Remarks

Call GetFormat with the format name when you need a Windows Clipboard numeric ID for an existing format.

Call this method with your own format name to create a new Clipboard format type. If the specified format does not exist, this method will register the name as a Clipboard format with the Windows registry and get a unique format identifier. This new name/ID pair will be added to the static list of format name/ID pairs in the DataFormats class.

See also

Applies to