如何将第一个文本保存在文本框中而不是覆盖它C#.NET(简单) [英] How do I save the first text in a textbox and not overwrite it C# .NET (simple)
问题描述
我正在开发一个非常基础的项目,我可以将其复制到剪贴板,并将其保存在我的应用程序的RichTextBox中。我已经通过计时器每隔0.5秒循环检查剪贴板,但是如何让第一个副本保留在TextBox中,因为它现在的作用是:
-I将东西复制到剪贴板
-它将它发送到TextBox
- 当我复制其他东西时它会覆盖它
如何让它们一个接一个地添加?
这是我到目前为止所得到的;
使用系统;
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;
命名空间 CBR
{
public partial class mainFrm:表单
{
public mainFrm()
{
InitializeComponent();
}
private void mainFrm_Load( object sender,EventArgs e)
{
}
private void clipboardUpdater_Tick( object sender,EventArgs e)
{
richTextBox1.Text = Clipboard。的getText();
}
}
}
我尝试了什么:
我试过了
richTextBox1.Text + = Clipboard.GetText();但是这只是一个接一个地添加,我需要让它只计数一次
而不是计时器使用剪贴板WM_CLIPBOARDUPDATE
: .net - 如何监控剪贴板内容的变化C#? - 堆栈溢出 [ ^ ]
还保存变量中的最后一个文本,然后从剪贴板中重新检查该文本和当前文本,如果有改变。
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. 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:
-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();
}
}
}
What I have tried:
I tried doing
richTextBox1.Text += Clipboard.GetText(); but that just adds one after the other, I need to make it only count once
Instead of a timer use the ClipboardWM_CLIPBOARDUPDATE
: .net - How to monitor clipboard content changes in C#? - Stack Overflow[^]
Also save the last text in a variable and recheck that and the current text from the clipboard and do your stuff if it has changed.
这篇关于如何将第一个文本保存在文本框中而不是覆盖它C#.NET(简单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!