Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi folks,

I am a bit blocked on this one and am open to any suggestions or alternatives.

 

I have a form with a background Image and I want to put Formatted text over it. This text varies so I can not incorporate it in the image.

 

I am currently using a Richtextbox but I have tried every form of background setting but I can not get it to be transparent with the background image being visible under the text.

 

Any suggestions:confused:

 

I have also notices a similar problem with the PictureBox controol.

 

 

Any help is greatly appreciated.

Hamlet
  • *Experts*
Posted
Instead of using a control, you could draw directly over the form using GDI+. In paint event, use the Graphics object that is passed in, and then use its DrawString method, you will be able to do all kinds of customizations as to how the font will look. As the text will be changing, create yourself another string variable that you will be able to modify, and tell the DrawString method to draw that string.
Posted
A problem with DrawString is that I can not pass a formatted string to it. For example the string I have is in RTF format with, Bold, Italics, and alternating text Colors. I can format this easily externally and pass it to the RichTextBox. I don;t think I can do the same with DrawString. If I have missed out on something here let me know..
Hamlet
  • Leaders
Posted
   Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       With e.Graphics
           .DrawString("some text", New Font("Tahoma", 20, FontStyle.Italic), New SolidBrush(Color.Red), e.ClipRectangle.X + 5, e.ClipRectangle.Y)
       '/// you can select rtf and then use the SelectionText / color / font properties within DrawString also
       End With
   End Sub

Posted

Hi folks,

I have banaged to get the background transparency problem solved by creating an inherited RichTextBox and setting up the styles in the constructor as follows

 

Me.SetStyle(ControlStyles.UserPaint, True)

Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)

Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)

Me.SetStyle(ControlStyles.DoubleBuffer, True)

 

I have tried it with different combinations of the above and get slightly varying results.

 

In all cases I get the background OK but I do not get the text.

 

I have also tried adding

 

Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)

Me.BackColor = Color.FromArgb(0, 0, 0, 0)

Me.ForeColor = Color.Black

End Sub

 

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

Me.ForeColor = Color.Black

MyBase.OnPaint(e)

End Sub

 

to see if it will add the text, but is doesn't

 

Any Suggestions

Hamlet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...