Download DesignerSnapLinesDemo.zip, last updated 19/04/2019 (8.39 KB)

Download
  • md5: 85fd7e0029eb045c195ad6eafab1a2f1
  • sha1: 4deddf404012c1456079d45d3072d41eb7c84495
  • sha256: d613c6fb34461e57632fceb6bdbd48ea1b4cb050f151d16d4a94c5c6a5446022
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using DesignerSnapLinesDemo.Design;

namespace DesignerSnapLinesDemo
{
  [Designer(typeof(BetterTextBoxDesigner))]
  //[Designer("DesignerSnapLinesDemo.Design.BetterTextBoxDesigner, DesignerSnapLinesDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
  internal class BetterTextBox : Control
  {
    #region Constants

    private const TextFormatFlags _flags = TextFormatFlags.EndEllipsis | TextFormatFlags.ExpandTabs | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine | TextFormatFlags.NoPadding;

    #endregion

    #region Constructors

    public BetterTextBox()
    {
      base.DoubleBuffered = true;
    }

    #endregion

    #region Methods

    /// <summary>Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event.</summary>
    /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data. </param>
    protected override void OnPaint(PaintEventArgs e)
    {
      Rectangle bounds;

      base.OnPaint(e);

      bounds = this.ClientRectangle;

      using (Brush brush = new LinearGradientBrush(bounds, Color.Orange, Color.OrangeRed, LinearGradientMode.Vertical))
      {
        e.Graphics.FillRectangle(brush, bounds);
      }

      e.Graphics.DrawRectangle(SystemPens.ControlDark, new Rectangle(0, 0, bounds.Width - 1, bounds.Height - 1));

      bounds.Inflate(-4, -4);

      TextRenderer.DrawText(e.Graphics, this.Text, this.Font, bounds, SystemColors.HighlightText, _flags);
    }

    #endregion
  }
}

Donate

Donate