FormSize 및 Text에 의해 Font 크기가 변한다.
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 GetterPrograms
{
    public partial class frmResizeFont : Form
    {
        public frmResizeFont()
        {
            InitializeComponent();
            frmResizeFont_Resize(null, null);
        }

        public Font AutoFontSize(Label label, String text)
        {
            Font ft;
            Graphics gp;
            SizeF sz;
            Single Faktor, FaktorX, FaktorY;
            gp = label.CreateGraphics();
            sz = gp.MeasureString(text, label.Font);
            gp.Dispose();

            FaktorX = (label.Width) / sz.Width;
            FaktorY = (label.Height) / sz.Height;
            if (FaktorX > FaktorY)
                Faktor = FaktorY;
            else
                Faktor = FaktorX;
            ft = label.Font;

            if(Faktor > 0)
                return new Font(ft.Name, ft.SizeInPoints * (Faktor));
            else
                return new Font(ft.Name, ft.SizeInPoints * (0.1f));
        }

        private void frmResizeFont_Resize(object sender, EventArgs e)
        {
            string str = label1.Text.ToString();
            label1.Width = panel1.Width - 10;
            label1.Height = panel1.Height - textBox1.Height - 10;
            label1.Font = AutoFontSize(label1, str);
        }

        private void frmResizeFont_FormClosing(object sender, FormClosingEventArgs e)
        {
            AssembleDelegate.SetEnable(true);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            label1.Text = textBox1.Text;
            label1.Font = AutoFontSize(label1, textBox1.Text);
        }

    }
}


Form Size에 의한 Font 사이즈 





 Text에 의한 Font 사이즈






Posted by 천사주니
,