Reputation: 2956
I'm Writing a program in WPF
(c#). I live in Iran so my language is persian(right to left
). I want to make a custom MessageBox
with more buttons or another controls.
I use a simple Window
to show messages. In C# when MessageBox is showing, user can not click or do any thing with another windows. How can I simulate
this, in my window?
In pervious I used WPFCustomeMessageBox library. please do not refer it to me.
Upvotes: 3
Views: 1214
Reputation: 1505
EDIT: It seems I didn't read the question carefully, and thought the issue was about not being able to use Right-To-Left alignment in MessageBoxes (which is possible through MessageBoxOptions).
There is an overload of the MessageBox.Show()
method, that lets you specify MessageBoxOptions
. Some of these options regard right-to-left alignment.
I don't know the language(s) used in Iran, so you'll have to try with your own text, but here is how to specify the options (the last parameter of the method):
string message = "Test message.";
string caption = "RTL Test";
MessageBoxImage image = MessageBoxImage.Information;
MessageBoxButton button = MessageBoxButton.OK;
MessageBoxResult defaultResult = MessageBoxResult.OK;
MessageBox.Show(message, caption, button, image, defaultResult, MessageBoxOptions.RightAlign);
MessageBox.Show(message, caption, button, image, defaultResult, MessageBoxOptions.RtlReading);
MessageBox.Show(message, caption, button, image, defaultResult, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);
Here is a link to an MSDN article about the options: MessageBoxOptions Enum (Winforms)
Upvotes: 1
Reputation: 10969
Use Window.Showdialog and do not forget to set the Window Parent, or you will get funny behavior.
Then in the Window class have properties for the expected returns, which are filled by the results of the dialog. Like:
public void testDialog()
{
var return = new DialogModelReturn();
mywindow.ShowDialog(new DialogModel(return));
if (return.isOk)
{
}
}
Something along this line of thought should work. Also: I would recommend to set the WindowStyle to none, or at least only a close Button, for the "ModalDialog feeling".
Like this:
<Window x:Class="bla.bla"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Fortschritt" Icon="bla.png" Height="200" Width="600"
WindowStyle="None" Background="RoyalBlue">
Upvotes: 1
Reputation: 9878
Use .ShowDialog()
to show a modal dialog:
MyMsgBox.ShowDialog()
This will stop the execution until the message box is closed. See MSDN Documentation.
Upvotes: 3