国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#編程實現(xiàn)查看剪切板內(nèi)容的方法

2020-01-24 01:21:13
字體:
供稿:網(wǎng)友

本文實例講述了C#編程實現(xiàn)查看剪切板內(nèi)容的方法。分享給大家供大家參考,具體如下:

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;//為傳送數(shù)據(jù)提供與格式無關(guān)的接口      string format = FormatString();      if (format == "Bitmap")      {        textBox1.Visible = false;        pictureBox1.Visible = true;        data = Clipboard.GetDataObject();//檢索位于當(dāng)前系統(tǒng)剪切板的數(shù)據(jù)        if (data.GetDataPresent(format))//確定此實例中存儲的數(shù)據(jù)是否與指定的格式關(guān)聯(lián),返回布爾        {          pictureBox1.Image = (Bitmap)data.GetData(format);//檢索與指定的格式關(guān)聯(lián)的數(shù)據(jù)          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里面數(shù)據(jù)的格式      if (radioButton2.Checked) format = DataFormats.Rtf;      if (radioButton3.Checked) format = DataFormats.Bitmap;      if (radioButton4.Checked) format = DataFormats.Html;      return format;    }  }}

運行程序后,如果之前復(fù)制過BITMAP圖,則TEXTBOX消失,PICTRUEBOX出現(xiàn),并且顯示該圖;反之如果選擇的是后三項,則TEXTBOX出現(xiàn),并且顯示復(fù)制過的值。效果圖如下:

這里有一個問題,如果把文字與圖片一起復(fù)制的話,就不能顯示了。感興趣的朋友可以加以完善。

希望本文所述對大家C#程序設(shè)計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 绥宁县| 海林市| 大洼县| 佛冈县| 西畴县| 呼图壁县| 黔江区| 绥宁县| 奈曼旗| 甘孜县| 贺兰县| 两当县| 葫芦岛市| 昭平县| 体育| 丰宁| 康乐县| 昌宁县| 邹平县| 邯郸县| 武山县| 勐海县| 阜新市| 桦南县| 广州市| 明光市| 绥中县| 冷水江市| 宁安市| 周口市| 遂宁市| 高青县| 邵武市| 枣庄市| 托克托县| 延庆县| 南通市| 凤山县| 图木舒克市| 临湘市| 廉江市|