How to create an Always On Top window?

  • Thread starter Anderson Takemitsu Kubota
  • Start date
A

Anderson Takemitsu Kubota

Hi,

Does anybody know how to create an Always on top window?
I have a form that will call a non maximized modeless window, and when I set
the focus for the first one, I don't want that it was hidden.
Any help?

Thanks,
Anderson
 
D

Dan Elliott [MSFT]

Anderson,

If I understand you correctly, you want a child window that will be
displayed on top of the main window when the main window is active. This
can be accomplished by setting the Parent property of the child window to
the form of the main window. For instance, if Form1 represents the main
window and Form2 the child window:

class public Form1
{
Form2 form2;

private void Form1_Load(object sender, System.EventArgs e)
{
this.form2 = new Form2();
this.form2.Parent = this;
this.form2.Show();
}

...
}

class public Form2
{
...
}


That said, here are some caveats:
* If you want the child form's border to be something besides
FormBorderStyle.None, you will need to set the FormBorderStyle property
twice during Form_Load. There is a bug that causes the child form to be
drawn without a border (FormBorderStyle.None) initially no matter what the
FormBorderStyle is set to. I've been able to work around this with the
following code:
private void Form2_Load(object sender, System.EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
}

* The child form's size will be set to the width of the parent form and
nearly the height of the parent form unless you explicitly set it in the
Form_Load method. For example:
private void Form2_Load(object sender, System.EventArgs e)
{
this.Size = new Size(124, 162);
}
* The title bar is not drawn in the active title bar color scheme when the
window has focus. I haven't found a workaround for this.
* Set the ControlBox property to false to get rid of the Ok button in the
title bar of the child form. It doesn't close the window or fire an event.

Hope this is helpful. If you have any questions, please let me know.
Dan

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top