调整特殊字体的大小

时间:2014-09-03 14:48:48

标签: winforms controls

我正在使用基于屏幕分辨率在运行时调整控件和文本的大小 以下例行程序。 除了诸如“Wingdings 3”之类的字体之外,这样工作正常。 “Wingdings 3”带来了实际的角色“Å”而不是“左箭头”。 有什么想法吗?

public void ResizeControls(Control objCtl)
    {
        foreach (Control cChildren in objCtl.Controls)
        {
            if (cChildren.HasChildren)
            {
                ResizeControls(cChildren);
            }
            else
            {
                cChildren.Size = new Size(Screen.PrimaryScreen.Bounds.Width * cChildren.Width / DesignWidth, Screen.PrimaryScreen.Bounds.Height * cChildren.Height / DesignHeight);
                cChildren.Location = new Point(Screen.PrimaryScreen.Bounds.Width * cChildren.Left / DesignWidth, Screen.PrimaryScreen.Bounds.Height * cChildren.Top / DesignHeight);

                if ((cChildren.GetType() == typeof(System.Windows.Forms.Label) | (cChildren.GetType() == typeof(System.Windows.Forms.Button))))
                    cChildren.Font = new Font(cChildren.Font.FontFamily.Name, Screen.PrimaryScreen.Bounds.Height * cChildren.Font.Size / DesignHeight, cChildren.Font.Style, cChildren.Font.Unit, ((byte)(0)));    // <-- HERE RESIZING A CONTROLS FONT PROPERTY 
            }
        }
        objCtl.Size = new Size(Screen.PrimaryScreen.Bounds.Width * objCtl.Width / DesignWidth, Screen.PrimaryScreen.Bounds.Height * objCtl.Height / DesignHeight);
        objCtl.Location = new Point(Screen.PrimaryScreen.Bounds.Width * objCtl.Left / DesignWidth, Screen.PrimaryScreen.Bounds.Height * objCtl.Top / DesignHeight);

        if ((objCtl.GetType() == typeof(System.Windows.Forms.Label)) | (objCtl.GetType() == typeof(System.Windows.Forms.Button)))
            objCtl.Font = new Font(objCtl.Font.FontFamily, Screen.PrimaryScreen.Bounds.Height * objCtl.Font.Size / DesignHeight, objCtl.Font.Style, objCtl.Font.Unit, ((byte)(0)));  // <-- HERE RESIZING A CONTROLS FONT PROPERTY 
     }

1 个答案:

答案 0 :(得分:1)

知道了。我将GDI字符集设置为0而不是复制字体原始GDI字符集。

"objCtl.Font.GdiCharSet"