Hello there !
I'm developing a Windows appliciation that involves so called "Transparen t Controls". As you would probably know, the only ( as far as i know ) way to achieve a fully transparent control in C# is to add the so called "Transparen t style" to your control ("WS_EX_TRANSPA RENT"). There are numerous articles how to achieve this and the method is ALMOST always one and the same:
And that works fine! ( well .... at least all say that ..... and all the articles say so ), but am i missing something or that method has SOME SERIOUS problems that nobody can see ?
For example the Z-order. The following piece of code creates simply a transparent control that draws a line accross itself with a random color:
And so ... when u put few "line controls" on top of each other the Z-ORDER goes to hell. You can't change it, its not corrent and it changes randomly each time u select a random "line control".
I've tried A LOT of methods to fix that ( changing the z-order in background, repainting the actual background because i think its because the background is not drawn ... and so on ). None works. I'm out of ideas and the worst part is i've almost finished the application and right in the end i realize that bug and it kills me.
Please help !!!

The "line controls" were added in the order shows 1,2,3 , but the Z-order appears to be different ( 1,3,2 ). In the current case "bring to front" , "send to back" doesnt change the Z-ORDER
I'm developing a Windows appliciation that involves so called "Transparen t Controls". As you would probably know, the only ( as far as i know ) way to achieve a fully transparent control in C# is to add the so called "Transparen t style" to your control ("WS_EX_TRANSPA RENT"). There are numerous articles how to achieve this and the method is ALMOST always one and the same:
Code:
protected override CreateParams CreateParams { get { CreateParams cp=base.CreateParams; cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT return cp; } } protected override void OnPaintBackground(PaintEventArgs pevent) { //do not allow the background to be painted }
For example the Z-order. The following piece of code creates simply a transparent control that draws a line accross itself with a random color:
Code:
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; namespace WindowsApplication16 { public class HrisTranspControl : Control { private Pen _drawingPen; public HrisTranspControl() { Random rnd = new Random(); this._drawingPen = new System.Drawing.Pen(new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(rnd.Next(0,255),rnd.Next(0,255), rnd.Next(0,255))),5); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; return cp; } } protected override void OnPaintBackground(PaintEventArgs pevent) { // Do nothing } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawLine(_drawingPen, new System.Drawing.Point(0, 0), new System.Drawing.Point(this.Width, this.Height)); } } }
I've tried A LOT of methods to fix that ( changing the z-order in background, repainting the actual background because i think its because the background is not drawn ... and so on ). None works. I'm out of ideas and the worst part is i've almost finished the application and right in the end i realize that bug and it kills me.
Please help !!!

The "line controls" were added in the order shows 1,2,3 , but the Z-order appears to be different ( 1,3,2 ). In the current case "bring to front" , "send to back" doesnt change the Z-ORDER
Comment