-1

So I've been messing around making a stock tracker for funsies, I've only got 1 more hurdle to overcome. That is: I want to make basicly everything in the app transparent except for text and borders.

I've tried various things I came across while googling such as

this.BackColor = Color.Magenta;
this.TransparencyKey = BackColor;

This worked except that it messed with the fonts/borders(?) of my Label text as well, resulting in this: Messed up fonts

I would love to know if there was a way to remove the shadows around the label texts, in that case this would be perfect.

I've tried other things as well, such as messing around with this:

protected override void OnPaintBackground(PaintEventArgs e)
{
  //variations of code here
}

That just completely messed up everything for a reason I am yet to understand, like this: messed up example 2

Then I went on to try mess around with variations of the following code, which seemed to do nothing at all:

this.SetStyle(ControlStyles.USerPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
// more variations of code

Maybe I haven't just read about all this enough (I don't understand the OnPaintBackground method at all) but I'm feeling kind of lost regardless. Anyone know an answer how to fix this?

  • I recommend you switch away from WinForms and at least use WPF, because WinForms does not support stacked controls, true transparency, and so on. Is there a reason you're using WinForms? – Dai Dec 05 '21 at 04:23
  • 1
    "I would love to know if there was a way to remove the shadows around the label texts, in that case this would be perfect." - I don't think those are "shadows", I think those are artifacts of subpixel antialiasing ("ClearType"). I suppose you could disable it so you can cleanly isolate text, but you'd also need to disable _all_ antialiasing, not just subpixel antialiasing - the end result will be clear and readable, but it won't be pretty (think: very 1995-looking). – Dai Dec 05 '21 at 04:24
  • I work at a company that uses WinForms in their software, thought I'd mess around with it to get a bit familiar. – borovanhout Dec 05 '21 at 04:27
  • 1
    Fair enough - self-improvement is a valid reason, after-all. But I do recommend that after you finish this, you try it again in WPF - if only to get a feel for how WPF is so very different. – Dai Dec 05 '21 at 04:28
  • @Dai Your answer did lead to something that works. Thanks a bunch for that! If you want to post it as the answer go ahead, else I'll post it to answer this myself I guess :) – borovanhout Dec 05 '21 at 04:36
  • @Dai Nevermind, just noticed I can't press buttons anymore now :( – borovanhout Dec 05 '21 at 04:41
  • Uhhh, what did you do to _almost_ make it work, exactly? – Dai Dec 05 '21 at 04:46
  • @Dai I responded as an answer to prevent this thread from growing out of hand – borovanhout Dec 05 '21 at 04:52

1 Answers1

0

@Dai, I tried this and made all the label text white, but yeah I can't press buttons anymore sadly

public Form1()
        {
            InitializeComponent();
            this.BackColor = Color.Magenta;
            this.TransparencyKey = BackColor;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            e.Graphics.DrawString(" ", Font, new SolidBrush(ForeColor), 0, 0);
        }

Any idea on a solution?

The result is basicly perfect, except that I can't press buttons anymore enter image description here

EDIT: Found the answer, Backcolor cant have a value where R & B are equal...