1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public partial class TextBox_TBR : TextBox
{
public TextBox_TBR()
{
// Le control se peint lui même
// Le control utilise un double buffer (anti-scintillement
// Le control supporte la transparence
// Le control ignore le messsage WM_ERASEBKGND pour reduire le scintillement
this.SetStyle(ControlStyles.UserPaint |
ControlStyles.DoubleBuffer |
ControlStyles.SupportsTransparentBackColor |
ControlStyles.AllPaintingInWmPaint, true);
InitializeComponent();
this.BorderStyle = BorderStyle.FixedSingle;
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
pevent.Graphics.FillRectangle(new SolidBrush(this.Parent.BackColor),
new Rectangle(0, 0, this.Width, this.Height));
}
protected override void OnPaint(PaintEventArgs e)
{
HauteurOptimal();
// Fond
GraphicsPath RRBackground = this.GetRoundedRect(new Rectangle(0, 0, this.Width - 1, this.Height - 1), 3F);
e.Graphics.FillPath(new SolidBrush(this.BackColor), RRBackground);
e.Graphics.DrawPath(new Pen(Color.FromArgb(183, 202, 234)), RRBackground);
// Texte
StringFormat sf = StringFormat.GenericTypographic;
sf.LineAlignment = StringAlignment.Far;
string _textResize = this.Text;
if (e.Graphics.MeasureString(_textResize, this.Font).Width > (this.Width - 3))
_textResize += "...";
while (e.Graphics.MeasureString(_textResize, this.Font).Width > (this.Width - 3))
_textResize = _textResize.Substring(0, _textResize.Length - 4) + "...";
e.Graphics.DrawString(_textResize, this.Font, new SolidBrush(this.ForeColor),
new Rectangle(5, -5, this.Width, this.Height),
sf);
sf.Dispose();
} |
Partager