473,379 Members | 1,491 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,379 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 5984
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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:
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.