C# MessageBox.Show——字体改变?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/232066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:09:15  来源:igfitidea点击:

MessageBox.Show-- font change?

c#fontsmessagebox

提问by mmr

I'm using the MessageBox class to show errors to users, and while that might not be the right behavior, it's very convenient. This is a touchscreen application, however, so I need the 'ok' button to be much larger than it is (curse my inordinately large fingers!).

我正在使用 MessageBox 类向用户显示错误,虽然这可能不是正确的行为,但它非常方便。然而,这是一个触摸屏应用程序,所以我需要“确定”按钮比实际大得多(诅咒我的手指过大!)。

I think that if I increase the font size in the dialog box, I should be ok. Is there a way to do that? Or really, is there any way to increase the dialog size?

我想如果我在对话框中增加字体大小,我应该可以。有没有办法做到这一点?或者真的,有什么办法可以增加对话框的大小?

Thanks

谢谢

采纳答案by Wim Hollebrandse

As far as I'm aware you can't, as the 'normal' dialog boxes are using your default system font settings.

据我所知你不能,因为“普通”对话框使用你的默认系统字体设置。

Roll your own is probably the best way forward. It's fairly trivial to do, and much fun! And you can build in things that the standard dialog doesn't support (without PInvoke magic) such as centering in the middle of the screen etc.

自己动手可能是最好的方法。做起来相当简单,而且很有趣!并且您可以构建标准对话框不支持的内容(没有 PInvoke 魔法),例如在屏幕中间居中等。

回答by Tass

I would create my own MessageBox class for this purpose - BigMessageBox perhaps?. It would then be a matter of replacing MessageBox.Show with BigMessageBox.Show.

为此,我会创建自己的 MessageBox 类 - 也许是 BigMessageBox?。然后就是用 BigMessageBox.Show 替换 MessageBox.Show 的问题。

Another alternative is using windows hooks to modify the form - have a look at https://web.archive.org/web/20091208060754/http://msdn.microsoft.com/en-gb/magazine/cc188920.aspxfor an example from .net 1.0. This may be easier in the current release, but I can't find an example for you.

另一种替代方法是使用窗钩修改形式-看看https://web.archive.org/web/20091208060754/http://msdn.microsoft.com/en-gb/magazine/cc188920.aspx用于来自 .net 1.0 的示例。这在当前版本中可能更容易,但我找不到适合您的示例。

回答by Sr.

Use a form with a Textbox and two Buttons OK, Cancel on it. Use this form instead of a MessageBox in the whole project. You can change the font, backColor, multiline etc of the textbox on the fly. You can change the size, color and font of the buttons too.

使用带有文本框和两个按钮的表单,在其上单击“确定”、“取消”。在整个项目中使用此表单而不是 MessageBox。您可以即时更改文本框的字体、背景颜色、多行等。您也可以更改按钮的大小、颜色和字体。

回答by Anatoliy Mogylevets

There is a solution -- via installing CBT hook it is possible to adjust on the fly wide variety of MessageBox visual settings: message and button fonts, dialog background, dialog positioning, icons, button captions, timeout and so on.

有一个解决方案——通过安装 CBT 钩子,可以动态调整各种 MessageBox 视觉设置:消息和按钮字体、对话框背景、对话框定位、图标、按钮标题、超时等。

Extended MessageBox .NET Assembly http://www.news2news.com/vfp/?solution=5

扩展 MessageBox .NET 程序集 http://www.news2news.com/vfp/?solution=5

回答by jreichert

please check out my free to use FlexibleMessageBoxwhich can be used instead of MessageBox and has a (static) FONT-Property.

请查看我的免费使用FlexibleMessageBox,它可以代替 MessageBox 使用并且具有(静态)FONT 属性。

Regards, J?rg

问候, J?rg