tags:

views:

458

answers:

2

I recently started using C# and WPF for one of my projects.

Is there a quick way of getting an input from the user? I have not been able to find one for WPF projects.

I don't want have to create another window, add OK and Cancel buttons, and add event handlers for everything. I can do it, but I wanted to know a simpler way of doing it.

AFAIK, that was possible in win forms. You can get user input with just one single line of code. Can I do it in WPF as well?

+1  A: 

If your talking about basic yes/no input then there is a wpf MessageBox that works in pretty much the same way as the winforms one - see System.Windows.MessageBox

Is that what you are thinking of?

Also, all winforms classes can still be used in WPF apps, you just need to add a reference to the appropriate assembly.

Simon P Stevens
No, I need to get an integer input. But text input is also fine which I can convert to integer. So a text box with OK/Cancel button is what I was looking for.
VNarasimhaM
Ahh....You're thinking of the InputBox, that's a hang over from visual basic in the pre .net days. (it might still be in vb.net). Check out Pete's answer for how to get to this in C#.
Simon P Stevens
+1  A: 

If you add the Microsoft.VisualBasic dll to your application, you can use the InputBox method to get a single value from the user.

Microsoft.VisualBasic.Interaction.InputBox("Prompt here", "Title here", "Default data", -1,-1);

(Put -1,-1 in for the XPos,YPos to get it centred on the screen)

Pete OHanlon
Nice one Pete, I'd totally forgotten about the InputBox, haven't used that since my VB4 days in high school.
Simon P Stevens
Good edit Simon. I feel dirty though;->
Pete OHanlon
You have to give the punters what they want =:)
Simon P Stevens