473,390 Members | 1,153 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

[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 5988
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
3
by: Colin McGuire | last post by:
Hi, I am just learning "how-to" by reading some of the existing article solutions in this newsgroup. I happened to come across this one. Tom Spink knows what he is talking about and I am wondering...
20
by: BB | last post by:
Hello all, I am trying to override OnPaint in a custom textbox control (so I can drawstring a caption, etc.). In the code below, I get the "painting the form" message as expected, but not the...
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
6
by: Tom P. | last post by:
I'm trying to make one of our perennial favorites - The Syntax Color Editor. (Mostly as a learning exercise). I'm wondering if there is a way to capture the Paint event of a textbox so I can...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.