[issue] overidding onPaint textbox to make lines causes problems

  • Thread starter Thread starter giddy
  • Start date Start date
G

giddy

hi when i run this class i made here , this is what it looks like
without text - > http://gidsfiles.googlepages.com/LinedTextBox_1.jpg
WITH TEXT (heres the issue) -
http://gidsfiles.googlepages.com/LinedTextBox_withText.jpg

The text turns BOLD and the lines kinda get erased because of the text.

perhaps i could overide or handle the onKeydown or somethin and
intercept the text to be entered and then draw it myself. Any
suggestions????????

this is the code :

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Linedtextbox
{
class LinedTextBox : System.Windows.Forms.TextBox
{
public LinedTextBox(): base()
{
Multiline = true;

SetStyle(System.Windows.Forms.ControlStyles.UserPaint,true);
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
int txtHeight = Convert.ToInt32(Font.GetHeight()) + 3;
Pen thePen = new Pen(Color.Black);
for (int i = txtHeight; i < Height ; i += txtHeight)
{
e.Graphics.DrawLine(thePen, 0, i, this.Width, i);
}

base.OnPaint(e);
}
}
}


Gideon
 
Call base onPaint first as this is drawing over your work. Call it first,
then you will be drawing lines over its results.
 
good thinking , i really hoped it would work but it did'nt work.

Also , if i type text and then cause a repaint (min the wndow , then
restore it) ... the text turns invsible , and the lines show .. but
then when i select the text . . ... poof! go the lines again , like in
the picture!

Gideon
 
good thinking , i really hoped it would work but it did'nt work.

Also , if i type text and then cause a repaint (min the wndow , then
restore it) ... the text turns invsible , and the lines show .. but
then when i select the text . . ... poof! go the lines again , like in
the picture!

Gideon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top