Solved

TextBox with Background Image or Gradient Color

Posted on 2004-08-12
4
1,608 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp web application 3 39
How can I do Unit Testing with Session ? 1 23
Selenium and Xpath 4 30
Convert VB web project to C# 3 37
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

749 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