【问题标题】:Telerik UI For WinForms RadMessageBox font sizeTelerik UI For WinForms RadMessageBox 字体大小
【发布时间】:2017-07-10 02:19:18
【问题描述】:

有没有一种方法可以增加整个应用程序的 RadMessageBox 的默认字体大小而无需创建自定义主题?

如果没有,如何在 Visual Style Builder 中增加默认主题的字体?我尝试只增加标签和按钮的字体大小,但样式生成器重置了承载消息框的整个表单,使其看起来非常简单并剪切了标签的文本(见随附的屏幕截图)。

谢谢。

【问题讨论】:

  • 为什么不创建自定义控件?也许你可以使用FlexibleMessageBox
  • 感谢 Odrai,因为我只想增加字体大小,我希望找到一种更简单的方法。最终,我可能不得不这样做。
  • 我已经在下面的消息中发布了答案。如果您有任何问题,请随时提出。

标签: telerik


【解决方案1】:

可以为应用程序中的所有 RadMessageBox 自定义字体。

  1. 实现一个在创建任何表单和/或 RadMessageBox 之前调用的方法 ('SetTelerikControlStyles')。您只需调用该方法一次!
  2. 在第1步创建的方法中添加如下代码行:

    RadMessageBox.Instance.FormElement.TitleBar.Font = new Font("Calibri", 25f);
    RadMessageBox.Instance.Controls["radLabel1"].Font = new Font("Calibri", 50f, FontStyle.Regular);
    

FormElement.TitleBar.Font,顾名思义,是 RadMessageBox 的标题栏。

Telerik 使用动态命名控件,因此在本例中 radLabel1 表示 RadMessageBox 文本区域。


完整的 Program.cs 示例:

using System;
using System.Drawing;
using System.Windows.Forms;

using Telerik.WinControls;

namespace WindowsFormsApplication
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SetTelerikControlStyles();

            Application.Run(new Form1());
        }

        private static void SetTelerikControlStyles()
        {
            RadMessageBox.Instance.FormElement.TitleBar.Font = new Font("Calibri", 25f);

            // I added this additional check for safety, if Telerik modifies the name of the control.
            if (RadMessageBox.Instance.Controls.ContainsKey("radLabel1"))
            {
                RadMessageBox.Instance.Controls["radLabel1"].Font = new Font("Calibri", 50f, FontStyle.Regular);
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 2021-01-27
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多