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.
Related
I am developing windows application to ask user to enter password in pop up box on that i am not able to put password mask,
if any on know could you please help me out this i am new to visual studio
string pin=Microsoft.VisualBasic.Interaction.InputBox("Input User Pin Number", "Pin Number", "" );
There is no easy way of doing this with an InputBox. (You'd have to install a hook before showing the dialog, and then when it was displayed, hunt around for its textbox control and change its styles.) Better to just say "can't". The InputBox wasn't designed to be customizable. In fact, it wasn't even designed to be used by .NET applications. It's an old classic VB thing, provided in the compatibility namespace merely to facilitate porting classic VB apps to VB.NET.
There is no real advantage in using it. Just create your own form with a label, maybe an icon, and a textbox. Set the textbox control's UseSystemPasswordChar property to true. (You could do as rashfmnb suggested and set the PasswordChar property, but it is better to use the system's password character instead of your own, that way it always matches the user's expectations.)
Be sure to display your new form with the ShowDialog method so that it will be a modal dialog (blocking call), just like InputBox.
user PasswordChar Property of the textbox
You can't mask the chars in an InputBox.
If you look at Interaction.InputBox Method on MSDN, there is no way to set it to be password input.
You will need to create a new Form, add your own Label and a TextBox, then set the PasswordChar property in the TextBox
I am familiar with the basics of Excel AddIns, but have no idea how to design, implement and later display an internal dialog.
See standing question with images here:
https://social.msdn.microsoft.com/Forums/en-US/935ebeae-1b88-4609-ba33-b0e522d2797f/how-to-create-a-dialog-for-use-by-an-excel-addin?forum=exceldev
TIA
Notes:
(1) My programming language is C#
(2) I prefer to design dialogs by drawing them.
You can use the MessageBox class, for example:
const string message =
"Are you sure that you would like to close the form?";
const string caption = "Form Closing";
var result = MessageBox.Show(message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
// If the no button was pressed ...
if (result == DialogResult.No)
{
// cancel the closure of the form.
e.Cancel = true;
}
If you want to customize the dialog window on your own, you can add a new Windows Form to the project and then add the required controls. After creating an instance of the form in the code you may show it using the Show or ShowDialog methods.
It would be nice to have larger MessageBox Buttons since the target for this application is a tablet.
DialogResult dialogResult = MessageBox.Show(
message, caption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
switch (dialogResult)
{
case DialogResult.Yes:
// ...
It is a system setting. Tablet PCs are normally already configured to make it easy to tap buttons like this so that it works well in any program, not just yours. To configure your tablet, in Win7, use Control Panel + Display, Personalization, Window Color. Click Advanced appearance settings, select "Message Box" in the Item combo. Increase the font size. Don't be fooled by the poor preview, the button will actually grow. There are additional settings in this dialog you might want to tweak to make it easier to manipulate the UI.
A messagebox is just a simple modal form. You can make one yourself and use ShowDialog()
I'm not sure if it's possible or not, but you could use a simple form instead of a dialog box then you can get the design exactly as you wish.
Winforms way? Do you mean, an "automagically via a property change" way? If so, none that I know of.
You can spin up your own custom dialog/form that is bigger and use it instead. While this is not as automagic as the one line MessageBox.Show(), it is not very difficult.
That's not possible with MessageBox which wraps the native system dialog.
You'll need to produce your own dialog or even better see if there is a way to configure the system to give your app (and all others) bigger buttons.
The downside of rolling your own is that you lose all the functionality that the native one provides.
Yeah, going along with what MattP said, you'll need to create a custom form and then use the ShowDialog() method to display the second form as a modal dialog.
private void button2_Click(object sender, System.EventArgs e) {
using (Form2 xForm = new Form2()) {
if (xForm.ShowDialog(this) == DialogResult.OK) {
// Take some action
}
}
}
You can make a 2nd form, then you can make the buttons as big as you want
I am currently developing an application in C# using WPF, I have always only used WinForms. Normally if I want to ask the user a question instead of making my own dialogue I use
DialogResult result = MessageBox.Show(
"My Message Question", "My Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
This is the first time that I have used a WPF form and DialogResult does not seem to be available. What do I use to get the same effect?
Here is how you do the same in WPF:
MessageBoxResult result = MessageBox.Show("My Message Question", "My Title", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
// Do this
}
Use MessageBoxResult instead. And use the MessageBox class. But this message box will look pretty ugly "classic" style.
Another option would be to use Extended WPF toolkit
Yet another option would be to go here and download CrossTechnologySamples.exe then look into the VistaBridge project. I recommend you give a good look here because you will find other samples for other dialogs (like FileOpen, FileSave etc.) that do not exist by default in WPF.
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?