Click here to Skip to main content
13,298,451 members (46,671 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 11 Feb 2013

How to get clipboard text in XNA

, 11 Feb 2013
Rate this:
Please Sign up or sign in to vote.
Here we get clipboard text to use in an XNA app.


Here we want to get clipboard text in XNA, but as i did this similar to windows forms getting clipboard it gave me some error, that I should use STA thread. so here I'm explaining how to get clipboard text using System.Windows.Forms.

The clipboard is very important for users to paste their cheats and stuff in a game.

Using the code

We create a class with name clipboard and we put this code below in it.

Here I used another thread for my STA purposes, so I'm here avoiding conflict in multi threaded applications like games. The thread name is t. we wait until our thread get clipboard text and put it into clipboard.

After checking if there is any text in clipboard by Clipboard.ContainsText() we set clipboard string variable using the Clipboard.GetText() function.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Language_Learning_Application
    public class clsClipBoard
        string clipboard="";
        public String GetClipboardText()
            Thread t = new Thread(getClipboard);
            return clipboard;

        private void getClipboard()
            if (Clipboard.ContainsText())
                clipboard = Clipboard.GetText(TextDataFormat.UnicodeText);
                //Clipboard.SetText(replacementHtmlText, TextDataFormat.UnicodeText);

So wherever we need clipboard text we do it like this:

public clsClipBoard myclsClipBoard = new clsClipBoard()
string clipboard  =myclsClipBoard.GetClipboardText();

It was easy more explanation would be given if there may be any question.

Points of Interest

Here we learned how to get clipboard text cause it's important in giving our application product keys or cheats or many other tasks.


  • Started it on 2/9/2013.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Italy Italy

NODET 2003-2007
B.Sc. Electrical Power Engineering 2007–2012


T.G.D. Co.(Power,Software) July 2010 -February 2012
Artnous Co.(Power) July 2010 -February 2012
Savay Co.(Software) September 2011- July 2012

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 11 Feb 2013
Article Copyright 2013 by F.moghaddampoor
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid