C#編程完成檢查剪切板內容的辦法。本站提示廣大學習愛好者:(C#編程完成檢查剪切板內容的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#編程完成檢查剪切板內容的辦法正文
本文實例講述了C#編程完成檢查剪切板內容的辦法。分享給年夜家供年夜家參考,詳細以下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication49
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
radioButton1.Checked = true;
pictureBox1.Visible = false;
textBox1.Visible = true;
}
//“檢查”按鈕
private void button1_Click(object sender, EventArgs e)
{
IDataObject data;//為傳送數據供給與格局有關的接口
string format = FormatString();
if (format == "Bitmap")
{
textBox1.Visible = false;
pictureBox1.Visible = true;
data = Clipboard.GetDataObject();//檢索位於以後體系剪切板的數據
if (data.GetDataPresent(format))//肯定此實例中存儲的數據能否與指定的格局聯系關系,前往布爾
{
pictureBox1.Image = (Bitmap)data.GetData(format);//檢索與指定的格局聯系關系的數據
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
else
{
MessageBox.Show("格局不准確", "提醒");
}
}
else
{
textBox1.Visible = true;
pictureBox1.Visible = false;
data = Clipboard.GetDataObject();
if (data.GetDataPresent(format))
{
textBox1.Text = (string)data.GetData(format);
}
else
{
MessageBox.Show("格局不准確", "提醒");
}
}
}
private string FormatString()
{
string format = "";
if (radioButton1.Checked) format = DataFormats.Text;//獲得IDATAOBJECT外面數據的格局
if (radioButton2.Checked) format = DataFormats.Rtf;
if (radioButton3.Checked) format = DataFormats.Bitmap;
if (radioButton4.Checked) format = DataFormats.Html;
return format;
}
}
}
運轉法式後,假如之前復制過BITMAP圖,則TEXTBOX消逝,PICTRUEBOX湧現,而且顯示該圖;反之假如選擇的是後三項,則TEXTBOX湧現,而且顯示復制過的值。後果圖以下:


這裡有一個成績,假如把文字與圖片一路復制的話,就不克不及顯示了。感興致的同伙可以加以完美。
願望本文所述對年夜家C#法式設計有所贊助。