how to: c# prompt window or prompt box in c sharp

Hi Guys,

Nowadays I am working on a .NET based project. Even though my area is Web side of things like webservices etc I still have to work with Windows Forms etc. So yesterday I has this problem where I have to open a Prompt Dialog window just like we can do in JavaScript.

To my surprise C sharp does not have such control. Now what. I got hold of my colleague and asked him. He said best way is to create a Form with a Textbox and a Button. Grab user input and feed it to main Form.

So I end up writing this class which is not very intuitive but does the Trick

 

Now from your Main Form call this class as

 

 

 

name will now have value grabbed from the Prompt Form.

You can do all sort of thing with the Prompt form e.g. centering it, applying new theme etc

I hope this helps.

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.