Error al dibujar un text box
Publicado por Gonzalo (1 intervención) el 24/07/2007 10:00:05
Buenas, estoy intentando hacer un textbox personalizado para cambiarle un poco el formato de presentación. El problema es que al coger el foco me plantea un problema que no sé a que se deben. El primero es que el cursor de escritura se me mueve como si estuviese escribiendo con un tamaño de fuente distinto al que se utiliza para escribir el texto (que es el que tiene el text box en la propiedad font) y cuando selecciono un parte del texto esta se muestra a tamaño grande también. Si alguién pudiese ayudarme os dejo el código aquí por si acaso:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
int X = this.Width;
int Y = this.Height;
string texto = this.Text;
if (texto != null && texto.Length != 0)
{
if (this.Enabled)
{
e.Graphics.DrawString(texto, base.Font, new SolidBrush(this.ForeColor),
0, 2);
}
else
{
e.Graphics.DrawString(texto, base.Font, new SolidBrush(SystemColors.GrayText), 0, 2);
}
}
if (this.Focused && this.Enabled)
{
e.Graphics.DrawRectangle(new Pen(Color.Orange), 0, 0, X - 1, Y - 1);
}
else
{
e.Graphics.DrawRectangle(new Pen(Color.Black), 0, 0, X - 1, Y - 1);
}
base.OnPaint(e);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
int X = this.Width;
int Y = this.Height;
string texto = this.Text;
if (texto != null && texto.Length != 0)
{
if (this.Enabled)
{
e.Graphics.DrawString(texto, base.Font, new SolidBrush(this.ForeColor),
0, 2);
}
else
{
e.Graphics.DrawString(texto, base.Font, new SolidBrush(SystemColors.GrayText), 0, 2);
}
}
if (this.Focused && this.Enabled)
{
e.Graphics.DrawRectangle(new Pen(Color.Orange), 0, 0, X - 1, Y - 1);
}
else
{
e.Graphics.DrawRectangle(new Pen(Color.Black), 0, 0, X - 1, Y - 1);
}
base.OnPaint(e);
}
Valora esta pregunta


0