开发者

Prevent string from breaking to new line in MessageBox

Is there a way to prevent the MessageBox from breaking a string instead of just growing to the width of the string? I'm porting an old VB application and they use message boxes to present a sizabl开发者_开发技巧e amount of data to the user. I suppose I could create a form, but I've already started down this road, and would not like to have to go back.

Thanks.


The only (supported) way to have such control over how things get laid out here is to ditch the MessageBox helper class and build a custom Form class that does what you need.


We have dealt with this issue in the past be embedding newlines (\r\n) in the text of our message. MessageBox will grow vertically to honor the wrapping text. We used to have MessageBoxs so wide you couldn't even see the centered buttons, but now they show up fine.

Depending on the complexity of generating the message text and/or whether you have control over that, this may be your simplest solution. Otherwise, I think you will need to create your own form.

For example:

MessageBox.Show("Line1\r\nLine2\r\nLine3\r\nLine4", "MessageBox test");
MessageBox.Show("Line1 Line2 Line3 Line4", "MessageBox test");

The first line creates a MessageBox with 4 lines of text and the window has grown to the correct height to show all. The second line creates a MessageBox with a single line and the appropriate width to show the whole line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜