防止 MessageBox 中的字符串换行
有没有办法防止 MessageBox 破坏字符串,而不是仅仅增长到字符串的宽度?我正在移植一个旧的 VB 应用程序,它们使用消息框向用户呈现大量数据。我想我可以创建一个表单,但我已经开始走这条路了,不想再回去了。
谢谢。
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 sizable 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对这里的布局进行控制的唯一(受支持的)方法是放弃 MessageBox 帮助器类并构建一个自定义 Form 类来执行您需要的操作。
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.
我们过去曾通过在消息文本中嵌入换行符 (\r\n) 来处理此问题。 MessageBox 将垂直增长以适应换行文本。我们过去的消息框太宽了,你甚至看不到居中的按钮,但现在它们显示得很好。
根据生成消息文本的复杂性和/或您是否可以控制它,这可能是您最简单的解决方案。否则,我认为您将需要创建自己的表单。
例如:
第一行创建一个包含 4 行文本的 MessageBox,并且窗口已增长到正确的高度以显示所有内容。第二行创建一个带有单行和适当宽度的 MessageBox 以显示整行。
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:
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.