Solved

TextBox with Background Image or Gradient Color

Posted on 2004-08-12
4
1,626 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
"The resource cannot be found" 1 44
Selenium and Xpath 4 70
C# Get Current Exchange Rate from XE 9 42
SQL State HYT00. Timeout expired proplem 8 44
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

752 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