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
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
After checking if there is any text in clipboard by
Clipboard.ContainsText() we set
clipboard string variable using the
public class clsClipBoard
public String GetClipboardText()
Thread t = new Thread(getClipboard);
private void getClipboard()
clipboard = Clipboard.GetText(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.