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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I change the background look of a TexBox control. 1

Status
Not open for further replies.

CosmoGreco

Programmer
Sep 16, 2002
13
US
What should I do to use my own customized background look for a TexBox control?

I don't want only to change the background color, but set some kind of input mask or have a background picture displayed. When I type in, the text will go over this customized background.

Unlike some other controls, BackgroundImage property is not available for TextBox.

Thanks,
Cos
 
Perhaps think about writing your own windows component that extends TextBox. start by overriding onPaint and adding whatever background you want to in there.

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

g.drawImage(myImage, 0, 0, Width, Height);
g.drawString(Text, myFont, new SolidBrush(myColour), new Rectangle(0, 0, Width, Height);
}

you're probaly also going to want to draw a cursor and perhaps one or two other things. there will be methods in TextBox to do this, but i don't know what they are.

Note Bene - variables starting with 'my' should be set using your gumption. Text, Width and Height are defined and controlled by inherited code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top