示例#1
0
        private void RefillCharsPanel()
        {
            FontChar fc;

            try {
                _charsPanel.SuspendLayout();

                // empty panel

                _charsPanel.Controls.Clear();

                // add new. not particularly fast.

                using (Graphics g = CreateGraphics()) {
                    foreach (FontUtil.FontRange fr in FontUtil.GetFontUnicodeRanges(_sizedFont.GdiFont))
                    {
                        for (UInt16 code = fr.Low; code <= fr.High; code++)
                        {
                            char c;
                            int  width;

                            fc = new FontChar();
                            c  = Convert.ToChar(code);

                            // special case for space which we map to the width of a "-"

                            width = (int)g.MeasureString(c == ' ' ? "-" : c.ToString(), _sizedFont.GdiFont, PointF.Empty, StringFormat.GenericTypographic).Width;

                            fc.Text     = c.ToString();
                            fc.Font     = _sizedFont.GdiFont;
                            fc.Size     = new Size(width, _sizedFont.Size);
                            fc.Selected = _sizedFont.ContainsChar(c);
                            fc.Click   += OnClickFontChar;
                            fc.Tag      = c;

                            _charsPanel.Controls.Add(fc);
                        }
                    }
                }
                _preview.Font = _sizedFont.GdiFont;
                RefillPreviews();
            }
            finally {
                _charsPanel.ResumeLayout();
            }
        }