Hello!
I have a DrawingColorPanel class inheritable from the Panel class.
In it, I rewrite the onPaint method:

protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.FillRectangle(Brushes.Blue, 0, 0, 24, 24); e.Graphics.DrawRectangle(Pens.Black, 0, 0, 24, 24); } 

The trick is to assign a color from the penColorGlobal object of the Color type to my rectangle (FillRectangle).

 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.FillRectangle(penColorGlobal, 0, 0, 24, 24); e.Graphics.DrawRectangle(Pens.Black, 0, 0, 24, 24); } 

But I cannot do this because the overloaded methods FillRectanlge () do not provide for the Color type.

Question: Is it possible to convert the penColorGlobal object into Brush type (Brushes) and if so, how? If there are other methods how to do this please write :)
Thank you in advance!

    1 answer 1

     protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Brush br = new SolidBrush(penColorGlobal); e.Graphics.FillRectangle(br, 0, 0, 24, 24); } 
    • Thank you very much! This is what I needed) - MikroFF