剪贴板功能 [英] ClipBoard Functionality
本文介绍了剪贴板功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
新年快乐.
我能够实现剪贴板功能,但我的疑问是我们无法从内容的复制位置得知.
场景:
1.我正在运行剪贴板应用程序.
2.打开记事本并复制一些内容.
3.我可以粘贴内容.
在这里,我要粘贴内容,如果是记事本,也要显示从记事本复制的内容;如果是从MS Word复制过来的,则要显示MS Word.
我的COde
Hi,
Happy New Year.
I am able to implement clipboard functionality and my doubt is can''t we know from where the content is copied.
Scenario:
1.I am running the clipboard application.
2.Opened notepad and copied some content.
3.I am able to paste the content.
Here i want to paste the content and also display like it''s copied from notepad if it is notepad or MS Word if it i Copied from MS Word.
My COde
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 Clipboard1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//copy Text
private void button1_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject(richTextBox1.SelectedText);
}
//Paste Text
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Text= Clipboard.GetText().ToString();
//if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text))
// textBox1.Text = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString();
//else
// textBox1.Text = "The clipboad does not contain any text";
//////label1.Text = Clipboard.GetText();
//// Retrieves data
//IDataObject iData = Clipboard.GetDataObject();
//// Is Data Text?
//if (iData.GetDataPresent(DataFormats.Text))
// label1.Text = (String)iData.GetData(DataFormats.Text);
//else
// label1.Text = "Data not found.";
}
//clearing ClipBoard
private void button3_Click(object sender, EventArgs e)
{
Clipboard.Clear();
}
//Copy Image
private void button4_Click(object sender, EventArgs e)
{
if (opnImage.ShowDialog() == DialogResult.OK)
{
Image imgToCopy = Image.FromFile(opnImage.FileName);
Clipboard.SetImage(imgToCopy);
}
}
//Paste Image
private void button5_Click(object sender, EventArgs e)
{
picClipboard.Image = Clipboard.GetImage();
}
}
}
推荐答案
检查是否有办法让剪贴板拥有者.
例如参见此线程 [ ^ ].它不在C#中,但可能会让您了解我要说的话.
Check if there is a way to get the clip board owner.
For e.g. see this thread[^]. Its not in C#, but it might give you an idea of what I''m trying to say.
这篇关于剪贴板功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文