Solved

RichTextBox BackgroundImage or alternatives

Posted on 2009-05-14
4
2,309 Views
Last Modified: 2013-12-17
I've created a program that I wanted to add skins to. Of course the label has a built in backgroundImage property, however richtextboxes don't... I successfully got overwrote the onpaint handler for the textbox but it doesn't paint the text over the background, I can only assume that somewhere along the way the background is getting painted over the text when the control is redrawn.

If there is an alternative control that allows me to format multiple lines of text with different font styles and colors, please do tell....otherwise i'm stuck trying to figure out how to get a background image on these things for my friend to make skins for my program.

Here's the code that works, but obviously not well enough:
public class myRichTextBox : RichTextBox

	{

		private Image IMAGE = Image.FromFile(Application.StartupPath + @"\custom\realTimeDisplay.jpg");
 

		public myRichTextBox()

		{

			base.SetStyle(ControlStyles.UserPaint, true);

		}
 

		public override Image BackgroundImage

		{

			get

			{

				return IMAGE;

			}

			set

			{

				IMAGE = value;

			}

		}
 

		protected override void OnPaint(PaintEventArgs e)

		{

			base.OnPaint(e);

		}

	}

Open in new window

0
Comment
Question by:Nitinol
  • 3
4 Comments
 
LVL 16

Expert Comment

by:CuteBug
ID: 24383228
0
 

Author Comment

by:Nitinol
ID: 24391800
I've found another solution, but when I set the selected text, it overlaps over the text...

Is there a way to keep it from overlapping?
	public class TransparentRichTextBox : RichTextBox

	{

		public TransparentRichTextBox()

		{

			base.ScrollBars = RichTextBoxScrollBars.None;

		}
 

		override protected CreateParams CreateParams

		{

			get

			{

				CreateParams cp = base.CreateParams;

				cp.ExStyle |= 0x20;

				return cp;

			}

		}
 

		override protected void OnPaintBackground(PaintEventArgs e)

		{

		}

	}

Open in new window

0
 

Author Comment

by:Nitinol
ID: 24392747
Anyone out there who can help me with the overlapping text problem when scrolling? Why is it so hard to put a background image on a box, when labels and other controls do it so easily?

I will also accept alternative controls that might do what I need them to do.

Thanks in advance.
0
 

Accepted Solution

by:
Nitinol earned 0 total points
ID: 24393599
well I decided to go with listview's instead since it appears i'm not going to get any help with transparency for the richtextbox.

Oh well. I tried. I've browsed about every post ever made on how to get a textbox to scroll once it's transparent, but with no luck.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

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

13 Experts available now in Live!

Get 1:1 Help Now