MessageBox.Show right to left reading not working

2019-06-20 04:57发布

Hey I'll make it simple. I want to make a MessageBox of this string "abc" and it will be read from right to left.

I tried this Messagebox.Show("abc",MessageBoxOptions.RtlReading);

what's worng with this ?

this is the error i get :

1:"cannot convert from 'System.Windows.Forms.MessageBoxOptions' to 'string"

2:"cannot convert from 'string' to 'System.Windows.Forms.MessageBoxButtons'"

3:"The best overloaded method match for 'System.Windows.Forms.MessageBox.Show(string, string)' has some invalid arguments"

4条回答
成全新的幸福
2楼-- · 2019-06-20 05:16

If it's not displaying left to right, try this:

//note the capitalized B in Box
MessageBox.Show(new string("abc".Reverse()), "", MessageBoxButtons.OK, MessageBoxIcons.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);

If you want something like this:

----------------------------X--
-------------------------------
|                             |
|                             |
|                        cba  |
|                             |
|                        |OK| |
-------------------------------

I think it doesn't have to do with that though, it's mainly you got the parameters wrong. wrong. Here, fixed:

//note the capitalized B in Box
MessageBox.Show("abc", "", MessageBoxButtons.OK, MessageBoxIcons.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);

There's also an ugly way to do this, but it means you don't have to add the extraparams. First, make a class called MessageBoxEx, and the contents of it are...

static class MessageBoxEx
{
    public static void Show(string content, MessageBoxOptions options)
    {
        MessageBox.Show(content, "", MessageBoxButtons.OK, MessageBoxIcons.None,          MessageBoxDefaultButton.Button1, options);
    }
}

and call it like MessageBoxEx.Show("abc", MessageBoxOptions.RtlReading);.

查看更多
霸刀☆藐视天下
3楼-- · 2019-06-20 05:19

I have been in situation like this, and the best way I found is to combine the two flags: RtlReading and RightAlign:

MessageBox.Show("Msg body", "Msg title", MessageBoxButton.OK, MessageBoxImage.Warning, 
         MessageBoxResult.OK, MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign);
查看更多
可以哭但决不认输i
4楼-- · 2019-06-20 05:20

The code you are using has a signature that matches MessageBox.Show(string, string) Which tries to display a string and a caption for the title. Instead, what you want is something that has all the arguments filled in:

MessageBox.Show("abc def","",MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
查看更多
老娘就宠你
5楼-- · 2019-06-20 05:25

Write a method that will default all the values you don't want to set.

//Message is the string message and options is where you specify RTL
public void ShowMessageBox(string message, MessageBoxOptions options)
{
    MessageBox.Show(message, "", MessageBoxButtons.OK, MessageBoxIcons.None, MessageBoxDefaultButton.Button1, options);
}

Then all you have to do is call

ShowMessageBox("abc", MessageBoxOptions.RtlReading)
查看更多
登录 后发表回答