Solved

TextBox with Background Image or Gradient Color

Posted on 2004-08-12
4
1,550 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now