Why is it not drawing an outline?

105 views Asked by At

so, i made an extra class called textlabel, because the normal windows forms label doesn't come with centered text, i also wanted to add an outline, but for some reason it doesn't draw the outline, even though , outline is set to true, outlinewidth is equal to 10 and outline color is gray(backcolor is lightgray)

namespace mynamespace._2D
{
    public class TextLabel : Control,IDisposable
    {
        public bool Outline { get; set; } = true;
        public Color OutlineColor { get; set; } = Color.Gray;
        public int OutlineWidth { get; set; } = 10;
        public int Transparency { get; set; } = 0;
        public bool MultiLine { get; set; } = true;

        private System.Timers.Timer PaintTimer = new(120);
      //Constructor...
        protected override void OnPaint(PaintEventArgs e)
        {
            if (!Visible) return;
            Rectangle rectangle = new(Location,Size);
            Graphics g = e.Graphics;
            if (Outline)
            {
                using Pen pen = new(OutlineColor, OutlineWidth);
                g.DrawRectangle(pen, new(Location, new Size(Size.Width - OutlineWidth, Size.Height - OutlineWidth)));
            }
            SizeF pixels = g.MeasureString(Text, Font);
            Point location = new(rectangle.Size.Width / 2 - (int)pixels.Width / 2, rectangle.Size.Height / 2-(int)pixels.Height/2);
            using Brush Textbrush = new SolidBrush(ForeColor);
            g.DrawString(Text, Font, Textbrush,location);
        }
     //rest of code...
    }
}

i tried overriding OnPaintbackground but that didn't help, it did the same thing as just doing everything in onpaint. i tried debugging using console, but for some reason no console.writeline() actually pop up in the console :(

if i override onpaintbackground it just becomes a black box in the clientrectangle and nothing affects it, no backcolors, nothing else is drawn either, just a black box. so i have stopped overriding onpaintbackground.

Thanks in advance!

0

There are 0 answers