示例#1
0
        /// <summary>
        /// Draws the control.
        /// </summary>
        /// <param name="e">Provides data for the <c>System.Windows.Forms.Control.Paint</c> event.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            string bufferString = "";

            // High quality text drawing.
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            // Define a tweaked rectangle for that the border was visible.
            Rectangle tweakedRectangle = new Rectangle(
                this.ClientRectangle.X,
                this.ClientRectangle.Y,
                this.ClientRectangle.Width - PEN_WIDTH,
                this.ClientRectangle.Height - PEN_WIDTH
                );

            /*
             * Text
             */

            using (StringFormat sf = NuGenControlPaint.CreateStringFormat(this, this.TextAlign, this.EatLine, true))
            {
                if (this.WordWrap == false)
                {
                    sf.FormatFlags |= StringFormatFlags.NoWrap;
                }

                if (this.TextOrientation == NuGenOrientationStyle.Vertical)
                {
                    sf.FormatFlags |= StringFormatFlags.DirectionVertical;
                }

                using (SolidBrush sb = new SolidBrush(this.ForeColor))
                {
                    g.DrawString(
                        this.text,
                        this.Font,
                        sb,
                        tweakedRectangle,
                        sf
                        );
                }
            }

            /*
             * Border
             */

            NuGenControlPaint.DrawBorder(g, this.ClientRectangle, NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, this.BorderColor), this.BorderStyle);
        }