Floating window makes parent flicker...

  • Thread starter Thread starter Iulian Ionescu
  • Start date Start date
I

Iulian Ionescu

Hi, I have the following problem: I designed a control
that acts similar to a combo box by dropping a small
window on click with some content. The control has a
private member of type ContainerPanel, which is a type I
defined as derived from form. I set all the properties
for this type so that it acts like a floating window (no
frame, no show in task bar, etc...). I override
OnActivate and set the focus back to the owner (which is
always the form that the controls lies on). However, when
the window is shown there is a very small flicker,
because for a fraction of a second the main form looses
focus and then gets it back. Is there any way to prevent
that? Should I use DestroyHandle to make sure the
floating window cannot receive focus?
I use the following routine to show the window:

NativeMethods.ShowWindow((IntPtr)base.Handle, 8);

then I have this:

protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
if (base.Owner != null)
{
base.Owner.Focus();
}
}

I would appreciate any ideas,

Thank you!
Iulian
 
Try adding this in your control's constructor:

// Reduce flicker

this.SetStyle(ControlStyles.DoubleBuffer, true);

this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);

// Redraw when resized

this.SetStyle(ControlStyles.ResizeRedraw, true);
 
Thanks, but that will not solve the problem. It is not
the new window that flickers it is the owner window that
does that because it looses focus for a fraction of a
second. Somebody suggested to override the WndProc and
don't let the WM_ACTIVATE message go through. I'll try
see if it works...

thanx
 
Back
Top