Clipboard programming in Visual C #

Source: Internet
Author: User

Visual C # is an important program development language in the Microsoft. NET Framework, although there are other programming languages in the. NET Framework, but Microsoft seems to be more interested in Visual C #. This also determines the position of Visual C # in the. NET Framework and his future prospects. Because the programming for the shearing board is always a focus of programming, of course, it can be regarded as a difficult point. This article explores how to use Visual C # for Clipboard programming. This article combines two specific program examples to describe the two important aspects of Visual C # Clipboard Programming: Determining the data type in the Clipboard, and saving the data in the Clipboard. Let's begin by describing how Visual C # determines the data type in the Clipboard.

There are many types of data that can be stored in the Clipboard. Visual C # can determine that there are roughly 21 types of data in the Clipboard, including bitmaps (Bitmap), text, hypertext (Html), and so on, because of the more type comparisons, this article will only cover the more typical data types. For other data types, the method of operation is basically similar.

A The design and operation Environment of this article:

(1) Microsoft company Windows 2000 Server Edition

(2). Net FrameWork SDK Beta 2

Two Describes the classes and interfaces that are used in the program:

Visual C # Determines the type of data in the Clipboard, using two classes (Class) and an interface (Interface) in the. Net FrameWork SDK, specifically: Clipboard class, DataFormats class and IDataObject interface. The three roles are: the Clipboard class is a class that cannot be inherited, and his main role is to store and obtain data in the computer system's Clipboard by its own method. The DataFormats class mainly provides a predefined clipboard data type and can be called by the IDataObject interface to determine the Clipboard data type. The IDataObject interface provides a free-form device to transmit data. The following is the combination of these classes and interfaces to specifically look at the specific use of the method.

Three Visual C # Determines the resolution of the Clipboard data type and the solution to the important steps:

(1). Read the contents of the Clipboard first:

The Clipboard class has a method called GetDataObject () that is used to read the contents of the data in the current clipboard. To store data that reads the current clipboard, this requires the IDataObject interface, which can be used in operations with clipboard classes and drag and drop. The following code reads the contents of the data in the current clipboard and stores it.

IDataObject d = Clipboard.GetDataObject ( ) ;

(2). Determine the type of data in the current clipboard:

In the IDataObject interface, a method name is GetDataPresent (), which is used to detect whether the data stored in the interface is of the specified data type or can be converted to the specified data type. His return value is a Boolean, and true is expressed as a specified data type or can be converted to the specified data type. False is opposite to the above meaning. The following statement implements the function of determining whether the current Clipboard data content is bitmap, text, and hypertext, as follows:

if ( d.GetDataPresent ( DataFormats.Bitmap ) ) {
Console.WriteLine ( "当前剪切板中的数据类型是位图!" ) ;
} else if ( d.GetDataPresent ( DataFormats.Text ) ) {
Console.WriteLine ( "当前剪切板中的数据类型是文本!" ) ;
} else if ( d.GetDataPresent ( DataFormats.Html ) ) {
Console.WriteLine ( "当前剪切板中的数据类型是超文本!" ) ;
} else {
Console.WriteLine ( "当前剪切板中的数据类型是其他类型数据!" ) ;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.