0

So I'm making a .Net Application and I have this textbox that is supposed to have the contents of your clipboard in it. But the Clipboard.GetText() does not import anything into the textbox, I've tried replacing it with "Hello World" and it works fine.

Code snippet:

bool running = true;

    public void GetClipboard()
    {
        while (running)
        {
            CurrentCopied.Text = Clipboard.GetText();
            System.Threading.Thread.Sleep(500);
        }
    }

    public Main()
    {
        InitializeComponent();

        ThreadStart CopyThreadStart = new ThreadStart(GetClipboard);
        Thread CopyThread = new Thread(CopyThreadStart);
        CopyThread.Start();
    }

1 Answers1

0

/*Try this */

public String GetClipboardText()
    {
        String returnHtmlText = null;
        if (Clipboard.ContainsText(TextDataFormat.Html))
        {
            returnHtmlText = Clipboard.GetText(TextDataFormat.Html);
           
        }
        return returnHtmlText;
    }
charithsuminda
  • 341
  • 2
  • 9
  • Sorry, I don't think that .NET textboxes can display HTML. I used the function you provided and set CurrentCopied.Text = returnHtmlText, it didn't work. –  Dec 02 '20 at 23:02
  • Oh, I might be an idiot. If a textbox is set to Read Only then does that mean I can't change it in code? –  Dec 02 '20 at 23:06
  • You can use it as function may be pass the value – charithsuminda Dec 03 '20 at 01:12