Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox subclassing

Status
Not open for further replies.

BLaZeXX

Programmer
Jul 19, 2003
6
CA
Hi,

I'm trying to make a little plus to the TextBox Control.

I want to make the TextBox Raised when the mouse is hover and and Flat when leave. That part works fine for me but the problem is that I got the text to disappear each time I'm leaving or entering the control.

BTW can someone point me to a good book only on control creation or a website (book preference)

Thanks a lot
jonathan.pouliot@tecksys.ca
 
i don't understand what you're asking, which probably means other don't too. you have a problem raising a textbox, except you don't and it works fine??

perhaps a code snippet would speak louder than words.
 
Inheriting from System.Windows.Forms.TextBox

bool IsOver = false;

protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
IsOver = true;
Invalidate();
}

protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
IsOver = false;
Invalidate();
}


protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics gr = e.Graphics;

if(IsOver)
{
ControlPaint.DrawBorder3D(gr,this.ClientRectangle,Border3DStyle.Raised,Border3DSide.all);
}
else
{
ControlPaint.DrawBorder3D(gr,this.ClientRectangle,Border3DStyle.Flat,Border3DSide.all);
}
}
 
hmmm. that's intersting, because i did a similar thing with a pictur box a little while ack and didn't get a problem. you might want to add 'this.Refresh();' to the end of each mouse releated method, so that it updates as soon as you enter/leav, but that's just speculation on my part.
 
Thanks for the suggestion, but it's doesn't work :(

anyway if u try the code I gave you will see that the TextBox won't change anything when you are passing on and out of it. I have to :
SetStyles(ControlStyles.UserPaint,true);

and then now it's very weird for me.

if u want to understand me well you try the code i gave. You will see.

Thanks
 
the more traditional way of beautifying your components is like this, which may help.

add this line in your constructor:

Paint += new System.Windows.Forms.PaintEventHandler(extraPaint);

now add the method 'private void extraPaint(object sender, System.Windows.Forms.PaintEventArgs e)' which will replace your OnPaint override (NB you won't need 'base.OnPaint(e)' now).

now do the same for you mouse events, and you could be on to a winner.

your problem may be that your component is refreshing at the wrong time, so this could sort you out.
 
Doesn't work

I really need to include
SetStyle(ControlStyles.UserPaint,True);

And I won't because now i have to remake the entire control

the only thing i want is make a bevel effect when my mouse passing over the control

I think this is the problem with the TextBox control (you can't)

any other controls will work perfectly

it's really weird
 
then you should include it. i don't know where you have the 'setstyle' call now, but i'd put it in the constructor. it won't stop you from using the event rather than overriding the current set of methods.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top