469,283 Members | 2,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

[issue] overidding onPaint textbox to make lines causes problems

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/Lin...x_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.UserPa int,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

Jan 1 '07 #1
4 5824
Call base onPaint first as this is drawing over your work. Call it first,
then you will be drawing lines over its results.

--
Ciaran O''''Donnell
http://wannabedeveloper.spaces.live.com
"giddy" wrote:
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/Lin...x_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.UserPa int,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

Jan 2 '07 #2
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

On Jan 2, 2:47 pm, Ciaran O''''Donnell
<CiaranODonn...@discussions.microsoft.comwrote:
Call base onPaint first as this is drawing over your work. Call it first,
then you will be drawing lines over its results.

--
Ciaran O''''Donnellhttp://wannabedeveloper.spaces.live.com

"giddy" wrote:
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/Lin...x_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.UserPa int,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
Jan 3 '07 #3
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

On Jan 2, 2:47 pm, Ciaran O''''Donnell
<CiaranODonn...@discussions.microsoft.comwrote:
Call base onPaint first as this is drawing over your work. Call it first,
then you will be drawing lines over its results.

--
Ciaran O''''Donnellhttp://wannabedeveloper.spaces.live.com

"giddy" wrote:
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/Lin...x_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.UserPa int,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
Jan 3 '07 #4

hey i figured it out:

hey! . .i got it!!!!! .. .

1. Raise a OnPaint manually from WndProc()
2. Keep causing a repaint everytime text is typed!

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;
}
protected override void WndProc(ref
System.Windows.Forms.Message m)
{
if (m.Msg == 0x00f)
{
// raise the paint event
base.WndProc(ref m);
Graphics graphic = base.CreateGraphics();
OnPaint(new
System.Windows.Forms.PaintEventArgs(graphic, base.ClientRectangle));
graphic.Dispose();
}
else
base.WndProc(ref m);
}
protected override void OnTextChanged(EventArgs e)
{
Graphics graphic = base.CreateGraphics();
OnPaint(new System.Windows.Forms.PaintEventArgs(graphic,
base.ClientRectangle));
graphic.Dispose();
base.OnTextChanged(e);
}
protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
int txtHeight = Convert.ToInt32(Font.GetHeight()) + 1;
Pen thePen = new Pen(Color.Black);
for (int i = txtHeight; i < Height ; i += txtHeight)
{
e.Graphics.DrawLine(thePen, 0, i, this.Width, i);
}
}
}
}
On Jan 3, 7:51 pm, "giddy" <gidisr...@gmail.comwrote:
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

On Jan 2, 2:47 pm, Ciaran O''''Donnell

<CiaranODonn...@discussions.microsoft.comwrote:
Call base onPaint first as this is drawing over your work. Call it first,
then you will be drawing lines over its results.
--
Ciaran O''''Donnellhttp://wannabedeveloper.spaces.live.com
"giddy" wrote:
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/Lin...x_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.UserPa int,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
Jan 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Colin McGuire | last post: by
14 posts views Thread by raylopez99 | last post: by
6 posts views Thread by Tom P. | last post: by
13 posts views Thread by SAL | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.