?
Solved

RichTextBox BackgroundImage or alternatives

Posted on 2009-05-14
4
Medium Priority
?
2,711 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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

749 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