Solved

TextBox with Background Image or Gradient Color

Posted on 2004-08-12
4
1,594 Views
Last Modified: 2008-01-09
Hi,

Currently I am  creating TextBox which is Inherited from the System.Windows.Forms.TextBox. Now I want to Paint BackColor my Self like

Gradient Color or Bitmap

Now I want some solution that how i can paint the back of textbox.

Actually my idea is to provide the TextArea which has Watermark like feelings. or Developer can used it for the future development without any trouble.

Thank you
Shrenik
0
Comment
Question by:jhaverisk
4 Comments
 
LVL 20

Accepted Solution

by:
TheAvenger earned 63 total points
ID: 11782923
Have a look at this article. It will give you an idea how you can paint the text box yourself. So you will be able to either paint it with gradient or put a bitmap under it (by also painting it):

http://www.codeproject.com/cs/miscctrl/alphablendtextbox.asp
0
 
LVL 2

Assisted Solution

by:davidastle
davidastle earned 62 total points
ID: 11788267
Just override the OnPaintBackground function

Fore example:
using System.Drawing;
using System.Windows.Forms;

namespace BitmapTextBoxNamespace
{
      public class BitmapTextBox : TextBox
      {
            private Bitmap myBitmap = null;
            public BitmapTextBox(string imagePath)
            {
                  try
                  {
                        myBitmap = new Bitmap(imagePath);
                        this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                              ControlStyles.UserPaint, true);
                  }
                  catch (System.NotSupportedException)
                  {
                        MessageBox.Show("Error: bitmap " + imagePath.ToString()
                              + " could not be created.  Invalid file path.");
                  }

            }
            protected override void OnPaintBackground(PaintEventArgs pevent)
            {
                  base.OnPaintBackground (pevent);
                  pevent.Graphics.DrawImage(myBitmap, pevent.ClipRectangle);
            }
      }
}

Draws a on the background of a textbox.  The problem is that when you type text, the background on the text is not transparent.  You have to pay me more points to try to solve this problem though!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question