form losing topmost state

G

Guest

Is there something that can change the TopMost=true status of a form to
become false at a later time during running?

My code only has the statments
this.TopMost = true;

A search for TopMost only finds these statements within
#region Windows Form Designer generated code

I am testing with Notepad.exe active and maximized. My L-shape (see
following description) should appear on the bottom and right of the
screen...even while I am typing in Notepad. Everything works for a while
until I open a new form. This new form is opened with ShowDialog() and has a
datagrid control on it...not sure if this makes any difference...although an
empty form with no controls does not cause the TopMost status of its parent
to be lost.

My application includes four forms that are displayed in TopMost, so they
always appear in the bottom 200 pixels and right 200 pixels of the screen.
IOW each form is responsible for painting part of the L-shape. The L-shape
acts like a task bar in that it is always topmost.

All four forms have the same parent. It is my Form1, and it has a window
frame. The other four forms have FormBorderStyle=None. My Form1_Load creates
the other four forms.
// create child windows
PeopleWaiting wPW = new PeopleWaiting();
wPW.Owner = this;
wPW.Show();
DisplayPlate wDP = new DisplayPlate();
wDP.Owner = this;
wDP.Show();
DisplayScene wDS = new DisplayScene();
wDS.Owner = this;
wDS.Show();
ReportLauncher wRL = new ReportLauncher();
wRL.Owner = this;
wRL.Show();

Form1 becomes invisible to the user, because its size and location puts it
directly behind the PeopleWaiting form.

Everything works well until I create a sixth form in my application. It is
created with the button click of the ReportLauncher form.
Form6 r = new Form6();
r.Owner = this; // this is the ReportLauncher form
r.ShowDialog();

Everything works well means.
1) I mouseclick on Notepad and I can type characters while I see my L-shape
of forms. Notepad's scroll bars and window control buttons are covered by my
L-shape.
2) I mouseclick somewhere on PeopleWaiting and Notepad title bar becomes gray.
3) I mouseclick somewhere on Notepad and the title bar becomes blue, while I
can see my L-shape of forms.
4) I continue to type characters into Notepad.

My L-shape looses its TopMost status after the following steps
4) I mouseclick on a button of the ReportLauncher form and it creates a new
popup form
5) I close Form6 by clicking its close button
6) I mouseclick on Notepad
7) Now, the maximize status of Notepad covers up the L-shape. Only Notepad
is visible on the screen.

How did the forms in my application get to the back of the Z-order?
 
K

Kevin Yu [MSFT]

Hi,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
J

Jeffrey Tan[MSFT]

Hi tgperfcodn,

Thanks for your post!!

After reading your detailed problem description, I think I understand your
problem: in your L-Sharp Winform application, 4 L-sharp forms all have the
TopMost state, but when we use ShowDialog() method to display a new form
with DataGrid control, this parent form's TopMost state is lost.

I have created a sample project for this issue and reproduced out your
issue. Yes, it seems it only occurs for modal form that contains DataGrid
control, even with an empty DataGrid control.

After reproduced out your problem, I did some search in internal database,
then I found a similiar known issue report with DataGrid control. I found a
public link for you:
"Bug Details: Topmost property not working for forms containing a Datagrid"
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=b
ecf3db8-85e2-44bc-ae4e-63f69682f46f

So, I think your problem should has something to do with this bug. Maybe
when ShowDialog make the modal dialog on top of our TopMost parent form,
with the above bug, it also faultly clear the parent form's TopMost state.

To workaround this issue, in Child form's Form_Load event, we can
re-position the parent form as TopMost state.(Note, we may first make the
parent form as the owner of the child modal form), code snippet lists below:

private void button1_Click(object sender, System.EventArgs e)
{
Form2 f=new Form2();
f.ShowDialog(this);
}

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
int Y, int cx, int cy, uint uFlags);

private const int HWND_TOPMOST=-1;
private const int SWP_NOSIZE=0x0001;
private const int SWP_NOMOVE=0x0002;

private void Form2_Load(object sender, System.EventArgs e)
{
SetWindowPos(this.Owner.Handle, (IntPtr)HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE|SWP_NOSIZE);
}
This works well on my side. Note: it seems that we need not P/invoke, in
Form2_Load event, this.Owner.TopMost=true also will get what we want.
===========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi tgperfcodn,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
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