This question already has answers here:
What is the C# version of VB.NET's InputBox?
(11 answers)
Closed 1 year ago.
I am wondering if c# has build-in input dialog, this dialog only has one(or only a few) text input and OK and Cancel button.
So I don't need to add a new form for such a simple job.
You can use System.Windows.Forms.MessageBox.Show to create a message box and specify that you only want an Ok and Cancel button:
using System.Windows.Forms;
MessageBox.Show("Prompt", "Caption", MessageBoxButtons.OKCancel);
The Show method returns the button clicked as a System.Windows.Forms.DialogResult:
DialogResult rst = MessageBox.Show("Prompt", "Caption", MessageBoxButtons.OKCancel);
if(rst == DialogResult.OK)
MessageBox.Show("You clicked OK");
If you are asking how to create an input box, then the question has already been asked here What is the C# version of VB.net's InputDialog?, though I would recommend that you create your own version of an input box, because the VBA version is pretty ugly - that way you can also style the input box according to your desire.
Related
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to avoid multiple instances of windows form in c#
I want to show open form only once in an application without creating them as MDI form.
Before opening the form from your code, check the Application.OpenForms property and see if the form exists in the collection.
Something like:
if ((Application.OpenForms["Form1"] as Form1) != null)
{
//Form is already open
}
else
{
// Form is not open
}
You can just use show\hide methods for opening your form. You also need to initialize all form fields after each time you show this.
Use a boolean variable with default value false which you set to true once the form was shown, and check the variable on form opening.
This question already has answers here:
How to use PasswordBox as TextBox? [closed]
(4 answers)
Closed 5 years ago.
I am currently making a c# application, in which I am using a text box with property PasswordChar - •. However, this text box has a button like the one below:
However, as a student and amateur, I am unable to make an if code for the button, which when pressed, shows or hides the real numbers of the password.
I think it should be something like this:
private void metroTextBox1_ButtonClick(object sender, EventArgs e)
{
if (metroTextBox1.PasswordChar='\•') metroTextBox1.PasswordChar = '\0';
else metroTextBox1.PasswordChar = '\•';
}
but I think I have at least 1 mistake here.
Please, help!
Your mistakes are in this :
textBox1.PasswordChar = '\•'
You must use == instead of = and '•' instead of '\•'
textBox1.PasswordChar == '•'
It worth be added as #Cody Gray has already noted that it is better to use UseSystemPasswordChar
This question already has answers here:
Uwp navigation example and focusing on control
(2 answers)
Closed 6 years ago.
I have a Universal Windows Platform project that has a textBox element.
I'd like to set the focus to it when a Radio Button is clicked.
In the Radio Button click event, I can say:
txtBoxID.IsEnabled = true;
txtBoxID.Text = "";
But how do I set the focus? I saw some answers saying to use:
FocusManager.SetFocusedElement(
but my FocusManager class doesn't have that method.
edit: Solved, thanks. Just needed to know what argument to pass to SetFocus. The other fellow's question which was thought to be similar was regarding an event occurring after he set focus to his control.
All the code you need is:
txtBoxID.Focus(FocusState.Programmatic);
Method is defined in Control.
DialogResult result = MessageBox.Show("Do you want to delete?", string.Empty, MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
if (result == DialogResult.No)
{
return;
}
And then i get popup Message with "Yes" and "No". Can i translate this two buttons and if yes how?
EDIT:
if anyone has similar problem look here:
http://www.christec.co.nz/blog/archives/134
No.
MessageBox.Show calls a native API function which shows a standard Windows dialog box.
The buttons will appear in the current system UI language.
If you want more control, create your own form.
If you're talking about the 'Yes'/'No' text in the popup, the text defaults to the local language set by the OS.
If you want to localize them to some other language, you'll have to implement your own MessageBox-like class.
On a computer with Russian language set a default UI language, your TextBox will display Da (Да) and Net (Нет) automatically instead of Yes and No. So basically you don't need to localize these.
P.S. Same applies to other UI localizations.
I am using Windows Form application. I want to open a small textbox on a window to enter user's name or Email in Starting for the program.
How can I achieve this?
Write one, 'tis almost trivial (creating the form and adding label, textbox and buttons) and using the VB one is perputating something that was only put in to appease the baying mob.
Key method is ShowDialog() which is a method on a Form.
On the form make sure you set the flags for the Ok and Cancel buttons correctly and provide a property (ideally) to allow you to read (and write if necessary) the text box
You can then do something along the lines of the following:
using(MyInputForm mif = new MyInputForm)
{
if (mif.ShowDialog() == DialogResult.OK)
{
dataFromDialog = mif.InputData;
}
else
{
// logic to deal with cancel
}
}
You can do something similar in WPF, don't have an example to hand though.
Maybe the answer to this question will help:
What is the C# version of VB.net’s InputDialog?