WPF messagebox localization - c#

Is there a way to change the Messagebox yes and no buttons text to something else ?
for example - Sí and No ?!

You can always make your own MessageBox. Just create a window with buttons and customize it the way you want to. Worked for me.

Try setting xml:lang='your languagecode' in the window where you call the messagebox from. Maybe that will work.
Edit: Google first hit: MessageBox buttons - set language?

Related

limiting tabbing to a custom in-window message box

I have made a custom MessageBox for my application and it launches as a UserControl. I have two buttons inside it and I would like to allow users to press Tab to switch between Buttons. However, since it's a UserControl overlaying the content, Pressing tab more than twice makes the focus go in the background on elements that aren't supposed to be tabbed at.
I can't figure out a good idea how to prevent this, I've thought of making a method that will select all elements and make their IsTabStop values to false and then restore them later, but I think that would be more of a problem then a solution.
Is there a way around this to limit tabbing only to the UserControl?
I would also appreciate advice on working with the message box.. the whole messagebox is an async function that has an infinitive loop until the answer is given. Is there another way to stop the application until one of the message box options was selected?
Crowcoder's reference has lead to correct MSDN page where I found my solution:
dialog = new UCMessageBox("Are you sure you want to exit the application?", MBType.YesNo);
AppMessageBox.Children.Add(dialog);
KeyboardNavigation.SetTabNavigation(dialog, KeyboardNavigationMode.Cycle);
The key was to call .SetTabNavigation function and direct it to my dialog (custom UserControl for the message box) and setting the KeyboardNavigationMode to Cycle.
After closing the UC rest of the application continued normally regarding navigation.

How to wait for a response from a wpf mvvm popup

I've searched but cannot find an answer to this question, and maybe that means there is a better way to do what I'm attempting.
In a WPF application, using MVVM design pattern: I've created a UserControl that is a box. This popup box has two options (buttons) on it, "Okay" and "Cancel". This user control has it's own view model to supply it's message data. Creating and showing this popup is simple enough. My trouble is I would like to wait for the users choice. Something similar to a DialogReponse? Ideally I would like to do something like this:
if (MyPopup.Show())
{
//do something
}
else
{
//do something else
}
Maybe there is a better approach to what I'm trying to do. I don't want to use a message box as I have the custom popup I've made. But maybe popup is the wrong control? Thanks ahead of time for any help.
If you want to have the functionality of a Window, why not use one?
new MyCustomDialogWindow().ShowDialog();
Use ShowDialog() method. For more information read MSDN

How to force a focus on a control in windows forms

I am trying to focus a "search" textbox control in my windows forms application. This textbox is inside a user control, which is inside a panel which is inside a windows form (if it is important).
I tried 3 methods which I could find:
// 1
this.ActiveControl = myTextBox;
// 2
myTextBox.Focus();
// 3
myTextBox.Select();
Neither of them seems to work. I mean for example when I try the first one, active control is really set to myTextBox, but when I try to write something on keyboard, textbox doesn't accept it and I have to first click inside the textbox to get focus. This is same with all of the methods.
Am I missing something?
Ok, finally found the answer:
As I said my textbox is inside user control which is inside panel which is inside a form.
When I need my user control I add it to panel. To get focus on my textbox I have to firstly focus my user control so something like this:
In my top Form:
panel.Controls.Add(myUserControl);
myUserControl.Focus();
and then in my user control:
myTextBox.Select();
Note that if I used: myTextBox.Focus() it wouldn't work (don't know why). Also if I used myUserControl.Select() instead of myUserControl.Focus() it wouldn't work either.
This seems to be the only combination which works.
You could do these logic steps to set your control to be the focus:
your_control.Select();
your_control.Focus();
Enjoy! :)

C#, do forms have an option to start with a certain button "selected"?

This was hard to explain, but say I have a form with a numeric up down. When the form starts, I want the number in the numeric up down to be highlighted meaning you can just press and number without clicking in the box and it will put it in there. How would I go about doing this?
EDIT: For some reason, doing .select() on the control with no parameters does select the control which is what I want. But using .select(0, 3) doesn't highlight the default "1" that is in the box. How do I highlight it?
You can Focus() the control and make the IsDefault property true to fires when pressing enter or returns (from another controls, as you need).
Just set the control's focus in the form's OnLoad event.
This should do the trick:
myNumericUpDown.TabIndex = 0;
myNumericUpDown.Focus();
myNumericUpDown.Select(0, myNumericUpDown.Value.ToString().Length);
Or swap out the select with:
myNumericUpDown.Select(0, 99);
Just put it in your form load :-)
EDIT:
The control also needs to have TabIndex set to 0
Just make sure no other control have TabIndex set to 0 :-)
You can start by putting focus on the numeric up down, that should let you do what you want.
Yes, you can call the Focus() method to set focus to a specific control.
E.g. in the constructor call myNumericUpDown.Focus();
I think you can just use the .Focus() method on the button in your code behind.
During the form load event try something like this ...
yourControl.Focus();
After InitializeComponents() you can call numericUpDown.Focus().
Set the ActiveControl property of the form and you should be fine.
this.ActiveControl = numericUpDown1
Inorder to get the text selected within the control, add this part
numericUpDown1.Select(0, numericUpDown1.Text.Length);

Form Closing event

I have a smartdevice project targeting windows mobile 6.
In the top right corner is an X (provided by the controlbox). i have an event on the form_closing that i was hoping would fire when the cross is clicked. But it doesnt :-(
Does anyone know why this event is not firing ???
Thanks :-)
John
Set the MinimizeBox property of your form to false. It's a weird thing about WinMo forms, but the X in the corner is really a minimize button, so it doesn't actually close the form. Setting MinimizeBox to false will replace the X with an OK button, and you'll get the form closing event.
Read this: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.closing.aspx
There are a number of possible reasons why theis could be happening, but I seriously doubt anyone will be able to guess why in this case, without you letting us see any of your code?

Categories

Resources