Note that there are some explanatory texts on larger screens.

plurals
  1. POOnPaint override cannot draw white text on top of picture boxes
    primarykey
    data
    text
    <p>I am writing an application that edits meta data of songs. To do this I have a window that has selected song tags and you can choose between the old and the new. I have a custom control with 3 pictureboxes in it for each tag box. One picture box for the left cap, one for the middle and one for the right cap. I then have overwritten OnPaint for the UserControl to draw the text onto the control. This works fine except when I try to use white text on top of a picture box that has an image in it. The white seems to become semi transparent. I have attached pictures below demonstrating this.</p> <p><strong>Black Text</strong> </p> <p><a href="http://bentrengrove.com.au/blackText.PNG" rel="nofollow noreferrer">Image of Black Text http://bentrengrove.com.au/blackText.PNG</a></p> <p><strong>White Text</strong></p> <p><a href="http://bentrengrove.com.au/WhiteText.PNG" rel="nofollow noreferrer">Image of White Text http://bentrengrove.com.au/WhiteText.PNG</a></p> <p><strong>Here is the code for my OnPaint method</strong></p> <pre><code>protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; Brush b; Font f; if (_isSelected &amp;&amp; this.Enabled) //Determines if the tag has the boxes visible, i.e is a selected tag { b = new SolidBrush(Color.White); f = new System.Drawing.Font("Segoe UI", 8, FontStyle.Regular); } else { b = new SolidBrush(Color.Gray); f = new System.Drawing.Font("Segoe UI", 8, FontStyle.Regular); } var textSize = g.MeasureString(_text, f); //We will resize the tag boxes based on the size of the text StringFormat drawFormat = new StringFormat(); drawFormat.Alignment = StringAlignment.Near; RectangleF layoutRectangle = new RectangleF(leftCap.Width, 1, textSize.Width, 16); if (textSize.Width &gt;= 105) _text = String.Format("{0}...", _text.Substring(0, 15)); //There is only so much room to display text middle.Width = (int)textSize.Width + rightCap.Width; rightCap.Left = middle.Left + middle.Width - rightCap.Width; g.DrawString(_text, f, b, layoutRectangle, drawFormat); //Draw the string for this control based on what has been set to text //Clean up g.Dispose(); b.Dispose(); f.Dispose(); } </code></pre> <p>Please if anyone has any ideas why I can't draw in white the help would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload