Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

TextBox with Background Image or Gradient Color

Posted on 2004-08-12
4
Medium Priority
?
1,776 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 252 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 248 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

971 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