Exemplo n.º 1
0
    protected override void OnKeyPress(KeyPressEventArgs kpea)
    {
        caret.Hide();
        Graphics grfx = CreateGraphics();

        grfx.FillRectangle(new SolidBrush(BackColor),
                           new RectangleF(Point.Empty,
                                          grfx.MeasureString(strText, Font,
                                                             Point.Empty, StringFormat.GenericTypographic)));

        switch (kpea.KeyChar)
        {
        case '\b':
            if (iInsert > 0)
            {
                strText = strText.Substring(0, iInsert - 1) +
                          strText.Substring(iInsert);
                iInsert -= 1;
            }
            break;

        case '\r':
        case '\n':
            break;

        default:
            if (iInsert == strText.Length)
            {
                strText += kpea.KeyChar;
            }
            else
            {
                strText = strText.Substring(0, iInsert) +
                          kpea.KeyChar +
                          strText.Substring(iInsert);
            }
            iInsert++;
            break;
        }
        grfx.TextRenderingHint = TextRenderingHint.AntiAlias;
        grfx.DrawString(strText, Font, new SolidBrush(ForeColor),
                        0, 0, StringFormat.GenericTypographic);
        grfx.Dispose();

        PositionCaret();
        caret.Show();
    }
Exemplo n.º 2
0
 /// <inheritdoc/>
 protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
 {
     base.OnLostKeyboardFocus(e);
     caret.Hide();
 }