C
C#14mo ago
Gipper

❔ 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
Pobiega
Pobiega14mo ago
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.
Gipper
Gipper14mo ago
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
Pobiega
Pobiega14mo ago
Im not sure what you mean by that.
if (InputDialog.ShowDialog("Username:", out var username) == DialogResult.OK)
{
label3.Text = username;
}
if (InputDialog.ShowDialog("Username:", out var username) == DialogResult.OK)
{
label3.Text = username;
}
public partial class InputDialog : Form
{
public InputDialog()
{
InitializeComponent();
}

public static DialogResult ShowDialog(string prompt, out string value)
{
var x = new InputDialog();
x.label2.Text = prompt;

var result = x.ShowDialog();

value = x.textBox1.Text;

return result;
}
}
public partial class InputDialog : Form
{
public InputDialog()
{
InitializeComponent();
}

public static DialogResult ShowDialog(string prompt, out string value)
{
var x = new InputDialog();
x.label2.Text = prompt;

var result = x.ShowDialog();

value = x.textBox1.Text;

return result;
}
}
extremely simple, but works
ffmpeg -i me -f null -
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.
Gipper
Gipper14mo ago
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?
Pobiega
Pobiega14mo ago
Ah I assumed winforms since you didn't specify
Gipper
Gipper14mo ago
I mean, it has the WPF tag at the top...
Pobiega
Pobiega14mo ago
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.
Pobiega
Pobiega14mo ago
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.
Accord
Accord14mo ago
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.
Want results from more Discord servers?
Add your server
More Posts
❔ Can someone help me use data from database tables?I have 2 $ and a dream ! Tommorow im going to the national stage of the c# olympiad and i dont even ❔ List string variablesHello, I'm really new to C# and would like to get help. How is the correct way to give variable for❔ EF successfully updated database, but unable to connect to sql server when getting data.Hey guys, getting back into .net after a while. sql server is currently on docker and I am able to c❔ ✅ Writing to response body is slow in .net core 7 web api?Hey guys, I have a stack overflow thread about the issue, but basically, I'm getting significant per❔ update-package : Failed to add reference to 'xyz'. Error HRESULT E_FAIL has been returnedSo I don't really know what happened. Turned my pc on, opened a project I created 2 days ago. My pac❔ help pleaseI’m try to make a 2d racing game in visual studio 2022 with C# but I’m have trouble figuring out how❔ Tailwindcss and . net7 proper installation using vs 2022 previewSo I got tailwind css working just not working properly. I cannot nest classes together like in vs cTrying to write to XAML file with C# (more details below)This might be too vague, and you're free to ask more questions about what I'm trying to get across, ❔ Learning C#, and curious about advanced return statements...I'm jumping right into the depts and wish to return a new object of 'Buffer' type and construct it w✅ How to make this loop```cs switch (chessPiece) { case "Knight": if(isSafe(cur