Transparency Control

So, trying to find some time, I eventually decided to ask about how to make the transparent controls display each other.

enter image description here

As you see in the picture, I have 2 transparent boxes with pictures, they show the background very well, but when it comes to the selected image, as you can see in the picture, it displays only the background image of the form, and not the other from the bottom. I know that there are general circumstances in winforms due to the lack of proper rendering, but the question arises:

Is there a way around this rendering glitch, is there a way to make the transparent controls rendered to each other?

Ok, this is the answer: Transparent images using C # WinForms

+4
source share
1 answer

The transparency of the control depends on its parent control. However, you can use a custom container control instead of the image window for the parent image. Maybe this code is usfull

using System; using System.Windows.Forms; using System.Drawing; public class TransparentControl : Control { private readonly Timer refresher; private Image _image; public TransparentControl() { SetStyle(ControlStyles.SupportsTransparentBackColor, true); BackColor = Color.Transparent; refresher = new Timer(); refresher.Tick += TimerOnTick; refresher.Interval = 50; refresher.Enabled = true; refresher.Start(); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x20; return cp; } } protected override void OnMove(EventArgs e) { RecreateHandle(); } protected override void OnPaint(PaintEventArgs e) { if (_image != null) { e.Graphics.DrawImage(_image, (Width / 2) - (_image.Width / 2), (Height / 2) - (_image.Height / 2)); } } protected override void OnPaintBackground(PaintEventArgs e) { //Do not paint background } //Hack public void Redraw() { RecreateHandle(); } private void TimerOnTick(object source, EventArgs e) { RecreateHandle(); refresher.Stop(); } public Image Image { get { return _image; } set { _image = value; RecreateHandle(); } } } 
+2
source

All Articles