MessageBox.Show() fonts

2019-04-25 02:20发布

问题:

Is there a way I can change the font types in a MessageBox.Show() to get bigger size, bold, italic styles?

回答1:

You can always make your own MessageBox creating a new Windows.Forms class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MessageBoxFont
{
    public partial class Message : Form
    {
        public Message(String text)
        {
            InitializeComponent();
            tbxMessage.Text = text;
            btnOK.Focus();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

Then you can control the properties (like the font, size, color and the like) shown under the solution explorer. You initialize this form like this:

        private void OpenMessageBox()
        {
            String text = "This is a sample error message";
            Message message = new Message(text);
            message.Show();
        }

Its a work-around, however, easier to implement :)



回答2:

I believe that those fonts are controlled by the operating system.

You could (however) make a custom dialog and put anything you want in there including custom fonts.
Here is the MSDN resource for custom dialogs.
http://msdn.microsoft.com/en-us/library/2chz8edb(VS.90).aspx



回答3:

Have you thought of something like a customized message box (www.html-messagebox.com)?

For more customization such as building an irregular shaped message box (Homer Simpson's head), you are better off creating your own MessageBox-like implementation for your project.



回答4:

Check this http://www.windowsdevelop.com/windows-forms-general/change-font-size-for-messageboxshow-dialogs-62092.shtml