locked
Give inactive form an active appearance RRS feed

  • Question

  • Hi

    On a form, I need to do some painting which appears on top of all the controls.  I do this by painting on a transparent form overlay, as described here . This solution works great, but there's a slight problem - while the transparent overlay is displayed, the main form becomes inactive, and so the text in the title bar is greyed out etc.  It would be nice if this didn't happen - I want the main form to appear active while the transparent overlay is displayed.  Is there any way to do this?

    Thanks
    Dominic
    • Edited by Dom31 Tuesday, May 26, 2009 7:12 AM
    Tuesday, May 26, 2009 7:10 AM

Answers

  • Instead of using a borderless overlay form, use one with the same border style:

        // Create a transparent form on top of <frm>
        mMask = new Form();
        mMask.FormBorderStyle = parent.FormBorderStyle;
        mMask.ControlBox = parent.ControlBox;
        mMask.Icon = parent.Icon;
        mMask.Size = parent.Size;
        mMask.Location = parent.Location;
        mMask.Text = parent.Text;
        mMask.BackColor = Color.Magenta;
        mMask.TransparencyKey = mMask.BackColor;
        mMask.ShowInTaskbar = false;
        mMask.StartPosition = FormStartPosition.Manual;
        mMask.MouseMove += MouseMove;
        //etc...




    Hans Passant.
    • Marked as answer by Dom31 Tuesday, May 26, 2009 8:50 AM
    Tuesday, May 26, 2009 8:47 AM

All replies

  • Instead of using a borderless overlay form, use one with the same border style:

        // Create a transparent form on top of <frm>
        mMask = new Form();
        mMask.FormBorderStyle = parent.FormBorderStyle;
        mMask.ControlBox = parent.ControlBox;
        mMask.Icon = parent.Icon;
        mMask.Size = parent.Size;
        mMask.Location = parent.Location;
        mMask.Text = parent.Text;
        mMask.BackColor = Color.Magenta;
        mMask.TransparencyKey = mMask.BackColor;
        mMask.ShowInTaskbar = false;
        mMask.StartPosition = FormStartPosition.Manual;
        mMask.MouseMove += MouseMove;
        //etc...




    Hans Passant.
    • Marked as answer by Dom31 Tuesday, May 26, 2009 8:50 AM
    Tuesday, May 26, 2009 8:47 AM
  • Yes of course!  Thank you
    Tuesday, May 26, 2009 8:50 AM
  • That's nice but incomplete IMHO. What if the underlying control is scrollable? Shouldn't MouseMove handler detect mouse being close to the edges and scroll accordingly?
    Thursday, March 26, 2015 12:27 PM