Solved

RichTextBox BackgroundImage or alternatives

Posted on 2009-05-14
4
2,340 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

12 Experts available now in Live!

Get 1:1 Help Now