简体   繁体   English

如何将第一个文本保存在文本框中而不覆盖它C#.NET

[英]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.

相关问题 如何阅读资源txt文件的文本并将其放入C#.net 4.0 WPF中的TextBox中? - How do I read the text of a resource txt file and put it into a TextBox in C# .net 4.0 WPF? 如何在C#Winforms程序的文本框中突出显示文本? - How do I highlight Text in a Textbox in a C# Winforms program? 如何在C#中替换文本框中的部分文本 - how do I replace part of text in textbox in c# 如何在 C# 中使用 StreamWriter WriteLine 逐行覆盖文本文件 - How do I overwrite a text file line by line using StreamWriter WriteLine in c# 如何在文本框(C#)中将多行(fasta格式)另存为一行? - How do I save a multi-line(fasta format) as one line in textbox (C#)? 在C#中的数字文本框中,如何防止仅将小数点放在第一位? - In C#, in a numerical textbox, how do I prevent a decimal point being placed in as the first digit only? 从C#中的文本框中保存带有文本的位图 - Save a Bitmap with Text from a textbox in C# C#ASP.NET Webforms:TextBox(Not Textbox.Text)空出。 您如何解决这个问题? - C# ASP.NET Webforms: TextBox(Not Textbox.Text) is coming out null. How do you fix this? 如何使用C#覆盖DOCX XML文件? - How do I overwrite a DOCX XML file with C#? 如何用另一种类型的值覆盖 C# 中的变量? - How do I overwrite a variable in C# with a value of another type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM