donnacha Posted October 16, 2003 Posted October 16, 2003 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. Quote Hamlet
*Experts* mutant Posted October 16, 2003 *Experts* Posted October 16, 2003 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. Quote
donnacha Posted October 16, 2003 Author Posted October 16, 2003 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.. Quote Hamlet
Leaders dynamic_sysop Posted October 16, 2003 Leaders Posted October 16, 2003 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 Quote
donnacha Posted October 16, 2003 Author Posted October 16, 2003 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 Quote Hamlet
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.