如何把字符串放到系统的粘贴板中,然后他在别的地方ctrl+v再粘贴出来实现复制粘贴功能!
大神们,该怎么做啊?
大神们,该怎么做啊?
解决方案 »
- 不显示删除回复显示所有回复显示星级回复显示得分回复 为什么我添加如下代码会出现错误呢??
- 如何使用Metefile类生成图元文件?
- 如何去判断一个类的实例是否存在?
- 如何取得用 DrawString() 函数绘制字符串的实际宽度啊?
- 请问有没有方法在单击框架中的页面链接后,保存当前框架页中的数据,再切换到另一个框架页???
- C# 导出Excel的问题
- 怎么得到网页的源代码
- 大家对C#的闭包有什么观点和看法吗?
- 大家快去看吧!亚太地区正在进行.net大赛。
- Unity怎么实现点击人物,旁边出现文字
- 如何清空GridView中的行
- WebClient.DownloadFile(uri,string)怎么使用
C# 实现复制,粘贴,剪切,撤销
using System;
using System.Windows.Forms;namespace ClickEvent
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Menu_Copy(System.Object sender, System.EventArgs e)
{
//确保文本在文本框中已经选定
if (textBox1.SelectionLength > 0)
// 复制文本到剪贴板
textBox1.Copy();
} private void Menu_Cut(System.Object sender, System.EventArgs e)
{
// 确保当前文本框中有选定
if (textBox1.SelectedText != "")
// 剪切选定的文本至剪贴板
textBox1.Cut();
} private void Menu_Paste(System.Object sender, System.EventArgs e)
{
// 判断剪贴板中是否有文本
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
{
// 判断文本框中是否有文本选定了
if (textBox1.SelectionLength > 0)
{
// 询问是否覆盖选定的文本
if (MessageBox.Show("你想覆盖选定的文本吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
// 移动选定文本的位置,即之前选定文本的起始+选定文本的长度
textBox1.SelectionStart = textBox1.SelectionStart + textBox1.SelectionLength;
}
// 将剪贴板中的文本粘贴至文本框
textBox1.Paste();
}
} private void Menu_Undo(System.Object sender, System.EventArgs e)
{
// 决定文本框最后的操作是否能撤销
if (textBox1.CanUndo == true)
{
// 撤销最后的操作
textBox1.Undo();
// 从该文本框的撤消缓冲区中清除关于最近操作的信息。
textBox1.ClearUndo();
}
}
}
}
System.Windows.Forms.Clipboard.SetText(text);