Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, so this is my code:
if (Clipboard.ContainsData(textBox2.Text))
                {
                    System.Diagnostics.Process.Start(@"notepad.exe");
        }


If the clipboard contains the data of textbox 2 then I want my application to open notepad. But every time I use "(Clipboard.ContainsData())" I get an error. Why? My program is not willing to see if the clipboard has the text of textbox 2..

What I have tried:

Posted
Updated 19-Mar-19 11:14am
v2
Comments
Mohibur Rashid 19-Mar-19 17:07pm    
What's the error?
j snooze 19-Mar-19 17:07pm    
If you get an error you should post the error message. Since we can't see your computer all details are necessary if you want help diagnosing. Is it possible textbox2.text is null so you can an object reference error or something?

1 solution

Clipboard.ContainsData does not check for "that data", it checks for a format: Clipboard.ContainsData(String) Method (System.Windows.Forms) | Microsoft Docs[^]
You would need to check for a type of data, and if your textbox doesn't contain a "real" format name, it probably throws an exception.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900