Solved

RichTextBox BackgroundImage or alternatives

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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