Solved the problem of endless flickering of transparent controls when the form first loads or is maximized. Couldnt find a solution anywhere on the NET after a strenuous search, so to give back for the countless times I have been helped by the online community, Im sharing it here:
It appears that sometimes when a transparent control paints itself, for some reason the display area of transparent controls in the lower z-order and the parent are invalidated, and an endless loop of WM_PAINT messages occurs. Override the WndProc function of the control. When the function receives the WM_PAINT message, call base.WndProc(ref m) and then call the ValidateRect Windows API as necessary, like so:
[Yeah, I know example is in C#. Started programming with VB6; I dont care where the solution comes from.]
[DllImport("user32", CharSet = CharSet.Auto, EntryPoint = "ValidateRect")]
public extern static Boolean ValidateRectangle(
IntPtr handle, // handle to window
IntPtr nullPointer); //type changed from ref RECT
private const Int32 WM_PAINT = 0x00f;
protected override void WndProc(ref Message m)
{
if(m.Msg == WM_PAINT)
{
base.WndProc(ref m);
ValidateRectangle(this.Parent.Handle, IntPtr.Zero);
foreach(Control control in this.Parent.Controls)
{
Int32 i3 = this.Parent.Controls.IndexOf(this);
Int32 i4 = this.Parent.Controls.IndexOf(control);
if(control is TransparentControlD)
{
if(i4 > i3)
{
continue;
}
}
ValidateRectangle(control.Handle, IntPtr.Zero);
}
}
else
{
base.WndProc(ref m);
}
}