I want to make a PictureBox that containts a round picture and a string. The shape of the Box should not be rectangular, but adapted to the String and the round Picture. I need this for achieving "perfect" transparency, because apparently WindowsForms, when set to transparent, just lets through the picture of the parent box.
Here is the code that I made:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
namespace myProject
{
class ShapedPictureBoxes : PictureBox
{
public ShapedPictureBoxes()
{
this.Paint += this.shapedPaint;
}
void shapedPaint(object sender, PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
Rectangle rectangle = this.ClientRectangle;
graphicsPath.AddEllipse(rectangle);
graphicsPath.AddString(text, new FontFamily("Arial"), (int)System.Drawing.FontStyle.Bold, 14f, new Point(0,0), new StringFormat());
e.Graphics.DrawString(text, new Font("Arial", 14f), Brushes.Red, new Point(0, 0));
this.Region = new Region(graphicsPath);
}
public string text = "HERE COMES THE SUN";
}
}
When using this class and assigning a picture to it, this leads to strange behavior:
- The text is not red, but white, there are some red particles in it, but mainly it is white. I assume that this comes from not identical Fonts. So how can I use the same font for both, the drawing and adding?
- The text is white exept for there, where it lays above the image: there, it is transparent and you can see through the form.
How comes this and how can I fix it?
on the left side you see how it currently looks like, on the right side you see the two different pictureboxes next to each other..
I want it to look like on the left side, but with a readable RED text..