❔ Better way to open a "window" to take in text input?
As in, when you click a button, a small window appears which exists only to take in the for example a
string name
with a box for the user to write the name into and maybe a text block saying something like "Enter name: ". The way I normally do this is add a whole new Window to the solution and make it do that. But I would like it possible to use something like a MessageBox to accomplish the same thing...Any luck?10 Replies
iirc there is no messagebox that has a text input field. You could very easily design your own thou, and make some convenience methods on it to more or less get that behaviour
MyInputBox.ShowDialog(out var name);
for example.Mmm, ok I'll do it that way...
Btw do you know any way in visual studio to create a "subsidiary" window?
As in to add this input window underneath the window that calls it and gets the data?
Just so it's nicely organized
Im not sure what you mean by that.
extremely simple, but works
there's still the old InputBox
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.interaction.inputbox?view=net-7.0
BUT you could eventually just create a little form in the code without having it in the project
it would be probably just a half page method, at most a page
Interaction.InputBox(String, String, String, Int32, Int32) Method (...
Displays a prompt in a dialog box, waits for the user to input text or click a button, and then returns a string containing the contents of the text box.
Sorry for the delayed response, can you explain what is happening here? I haven't worked with windows forms yet
Visual studio doesnt know about anything named Forms which you are inheriting there from...
and yes, I have written
using System.Windows.Forms
Hey guys, I've been googling around and it seems like this "page" feature that WPF has may work well for these purposes...Thoughts?Ah I assumed winforms since you didn't specify
I mean, it has the WPF tag at the top...
Fair. It's a shame they are so easy to miss
but to stay on topic, while you probably could use a
Page
it may not be what you want. If you think of a webpage, its more like going to "About us" more than its opening a modal with a textbox.https://learn.microsoft.com/en-us/dotnet/desktop/wpf/windows/dialog-boxes-overview?view=netdesktop-7.0 seems to be what you want
Dialog Boxes Overview - WPF .NET
Learn about the varieties of dialog boxes in Windows Foundation Presentation (WPF). With a dialog box, you gather and display information to a user.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.