Exemple #1
0
        /// <summary>
        /// Draw the label of the component. Method does nothing if <see cref="Label"/> is null or empty.
        /// </summary>
        protected virtual void DrawLabel(Graphics g)
        {
            if (string.IsNullOrWhiteSpace(Label))
            {
                return;
            }

            using (Font font = LabelStyle.CreateFont()) {
                SizeF size = g.MeasureString(Label, font); // XXX: Cache Graphics.MeasureString?

                using (Brush brush = LabelStyle.CreateBrush()) {
                    float ox = Width / 2f - size.Width / 2f;
                    float oy = Height + 2f;

                    g.DrawString(Label, font, brush, GlobalX + ox, GlobalY + oy);
                }
            }
        }