[英]How do I save the first text in a textbox and not overwrite it C# .NET
I am working on a very basic project where I can copy something to the clipboard and it saves it in a RichTextBox in my application. 我正在一个非常基本的项目中工作,可以在其中复制一些内容到剪贴板,并将其保存在应用程序的RichTextBox中。 I've made it loop through and check the clipboard every 0.5 seconds with a timer but how do I make the first copy stay in the TextBox because what it does now is: 我已经使其遍历并使用计时器每0.5秒检查一次剪贴板,但是如何使第一个副本保留在TextBox中,因为它现在的作用是:
-I copy something to the clipboard
-It sends it to the TextBox
-When I copy something else it overwrites it
How do I make them add one after the other? 如何使它们一个接一个地添加?
This is what I got so far; 这就是我到目前为止所得到的。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CBR
{
public partial class mainFrm : Form
{
public mainFrm()
{
InitializeComponent();
}
private void mainFrm_Load(object sender, EventArgs e)
{
}
private void clipboardUpdater_Tick(object sender, EventArgs e)
{
richTextBox1.Text = Clipboard.GetText();
}
}
}
Seems like this is what you're looking for; 看起来这就是您想要的;
private void clipboardUpdater_Tick(object sender, EventArgs e)
{
if (!richTextBox1.Text.Contains(Clipboard.GetText()))
{
richTextBox1.Text += Clipboard.GetText();
}
}
If you want to seperate each paste, replace the statement with this; 如果要分开每个粘贴,请用此语句替换;
richTextBox1.Text += " " + Clipboard.GetText();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.