Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

RichTextBox BackgroundImage or alternatives

Posted on 2009-05-14
4
Medium Priority
?
2,661 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
[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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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