Reputation: 439
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();
}
}
}
Upvotes: 2
Views: 80
Reputation: 586
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();
Upvotes: 3