C#編程實(shí)現(xiàn)查看剪切板內(nèi)容的方法
本文實(shí)例講述了C#編程實(shí)現(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í)例中存儲(chǔ)的數(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; } } }
運(yùn)行程序后,如果之前復(fù)制過BITMAP圖,則TEXTBOX消失,PICTRUEBOX出現(xiàn),并且顯示該圖;反之如果選擇的是后三項(xiàng),則TEXTBOX出現(xiàn),并且顯示復(fù)制過的值。效果圖如下:
這里有一個(gè)問題,如果把文字與圖片一起復(fù)制的話,就不能顯示了。感興趣的朋友可以加以完善。
希望本文所述對大家C#程序設(shè)計(jì)有所幫助。
上一篇:C#數(shù)據(jù)結(jié)構(gòu)之雙向鏈表(DbLinkList)實(shí)例詳解
欄 目:C#教程
本文標(biāo)題:C#編程實(shí)現(xiàn)查看剪切板內(nèi)容的方法
本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6803.html
您可能感興趣的文章
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新聞效果的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#實(shí)現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已安裝軟件變化的方法
- 01-10C#實(shí)現(xiàn)多線程下載文件的方法
- 01-10C#實(shí)現(xiàn)Winform中打開網(wǎng)頁頁面的方法
- 01-10C#實(shí)現(xiàn)遠(yuǎn)程關(guān)閉計(jì)算機(jī)或重啟計(jì)算機(jī)的方法
- 01-10C#自定義簽名章實(shí)現(xiàn)方法
- 01-10C#文件斷點(diǎn)續(xù)傳實(shí)現(xiàn)方法
- 01-10winform實(shí)現(xiàn)創(chuàng)建最前端窗體的方法


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
- 01-10WinForm實(shí)現(xiàn)仿視頻播放器左下角滾動(dòng)新
- 01-10C#停止線程的方法
- 01-10C#實(shí)現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實(shí)現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10delphi制作wav文件的方法
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05織夢dedecms什么時(shí)候用欄目交叉功能?
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 04-02jquery與jsp,用jquery
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11ajax實(shí)現(xiàn)頁面的局部加載