Cyotek Forums

Source Code => Source Code => Topic started by: Deer2014 on December 09, 2020, 04:45:23 PM

Title: ImageBox transparent background color
Post by: Deer2014 on December 09, 2020, 04:45:23 PM
Hi,

Is it possible to set the ImageBox background color to transparent?
As with a standard .NET System.Windows.Forms.PictureBox.
Is this not supported?  :(

Thanks,
Title: Re: ImageBox transparent background color
Post by: Richard Moss on December 10, 2020, 07:23:47 AM
Hello,

This isn't something that is currently supported, although I raised an issue on the source repository (https://github.com/cyotek/Cyotek.Windows.Forms.ImageBox) to add this in a future update.

In the meantime, you could try creating your own custom control that inherits from ImageBox and turns on the correct style, then it will automatically paint correctly (if the BackColor property is set to Transparent) as I haven't overridden default background painting.

public class MyImageBox : Cyotek.Windows.Forms.ImageBox
{
  public MyImageBox()
  {
      this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  }
}


I haven't fully tested this, but from a quick experiment changing the demonstration application it seems to work.

[attachment id=0 msg=1151]

Hope this helps.

Regards;
Richard Moss
Title: Re: ImageBox transparent background color
Post by: Deer2014 on December 10, 2020, 08:48:49 AM
Thanks, I'll try this.