ImageBox transparent background color

Started by Deer2014, December 09, 2020, 04:45:23 PM

Previous topic - Next topic

Deer2014

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,

Richard Moss

Hello,

This isn't something that is currently supported, although I raised an issue on the source repository 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
Read "Before You Post" before posting (https://forums.cyotek.com/cyotek-webcopy/before-you-post/). Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

Deer2014