Changing Visible property in Form changes location.

D

Doc John

I have an MDI container with a child Form which will be visible according to
certain events. The problem is that when I set the property Visible to False
and then back to True, the Form will be in another location, or it will be
maximized.

Why does the child Form change its location when the Visible propery is set
true (after being set to False)? Why doesn't it stay with the same Size and
the same Location?

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Doc,

Can you show an example where this happens? When setting the Visible
property to false, then back to true (I have a timer make the form visible
again) it comes back in the same place.
 
D

Doc John

Thanks for the post.

I have an MDI Container and a TabControl docked to the left (similar to the
Outlook interface). This tab control has two buttons: One that instantiates
the child Form frm_listBrowse, and another button (button_visible) that
calls a procedure in frm_listBrowse that sets the Visible property to false.
Assuming that I've already created an instance of frm_listBrowse, this is
the code in button_invisible in my tabcontrol:

Form[] childForm = this.MdiChildren;
Form_base myForm = new Form_base(); //all Forms inherit from Form_base
which includes method hideForm() and displayForm().
Form f;

for (int i = 0; i < childForm.Length; i++)
{
if (childForm.Name == "frm_listBrowse")
{
f = (Form)childForm;
myForm = f as frm_listBrowse;
if (!isSeen) // isSeen lets me know the status of the Form- Visible
or not
{
myForm.displayForm(); //sets Visible to true
isSeen = true;
}
else
{
myForm.hideForm(); //sets Visible to false
isSeen = false;
}
}
}




Nicholas Paldino said:
Doc,

Can you show an example where this happens? When setting the Visible
property to false, then back to true (I have a timer make the form visible
again) it comes back in the same place.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Doc John said:
I have an MDI container with a child Form which will be visible according
to certain events. The problem is that when I set the property Visible to
False and then back to True, the Form will be in another location, or it
will be maximized.

Why does the child Form change its location when the Visible propery is
set true (after being set to False)? Why doesn't it stay with the same
Size and the same Location?

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Well, that is by no means a complete example. The displayForm and
hideForm methods are doing something, and I imagine that the code that is
moving the forms is located somewhere in those methods.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Doc John said:
Thanks for the post.

I have an MDI Container and a TabControl docked to the left (similar to
the Outlook interface). This tab control has two buttons: One that
instantiates the child Form frm_listBrowse, and another button
(button_visible) that calls a procedure in frm_listBrowse that sets the
Visible property to false.
Assuming that I've already created an instance of frm_listBrowse, this is
the code in button_invisible in my tabcontrol:

Form[] childForm = this.MdiChildren;
Form_base myForm = new Form_base(); //all Forms inherit from Form_base
which includes method hideForm() and displayForm().
Form f;

for (int i = 0; i < childForm.Length; i++)
{
if (childForm.Name == "frm_listBrowse")
{
f = (Form)childForm;
myForm = f as frm_listBrowse;
if (!isSeen) // isSeen lets me know the status of the Form- Visible
or not
{
myForm.displayForm(); //sets Visible to true
isSeen = true;
}
else
{
myForm.hideForm(); //sets Visible to false
isSeen = false;
}
}
}




Nicholas Paldino said:
Doc,

Can you show an example where this happens? When setting the Visible
property to false, then back to true (I have a timer make the form
visible again) it comes back in the same place.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Doc John said:
I have an MDI container with a child Form which will be visible according
to certain events. The problem is that when I set the property Visible to
False and then back to True, the Form will be in another location, or it
will be maximized.

Why does the child Form change its location when the Visible propery is
set true (after being set to False)? Why doesn't it stay with the same
Size and the same Location?

Thanks.
 
D

Doc John

The methods hideForm() and displayForm() each have one line: "this.Visible =
false;" and "this.visible = true;".

I also created a new Form that also inherited from Form_base to see if it
had something to do with my Form, but it does the same thing. It moves about
1/2-inch to the bottom and to the right. After about five clicks, it'll move
back to the top.

Thanks again.

Nicholas Paldino said:
Well, that is by no means a complete example. The displayForm and
hideForm methods are doing something, and I imagine that the code that is
moving the forms is located somewhere in those methods.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Doc John said:
Thanks for the post.

I have an MDI Container and a TabControl docked to the left (similar to
the Outlook interface). This tab control has two buttons: One that
instantiates the child Form frm_listBrowse, and another button
(button_visible) that calls a procedure in frm_listBrowse that sets the
Visible property to false.
Assuming that I've already created an instance of frm_listBrowse, this is
the code in button_invisible in my tabcontrol:

Form[] childForm = this.MdiChildren;
Form_base myForm = new Form_base(); //all Forms inherit from Form_base
which includes method hideForm() and displayForm().
Form f;

for (int i = 0; i < childForm.Length; i++)
{
if (childForm.Name == "frm_listBrowse")
{
f = (Form)childForm;
myForm = f as frm_listBrowse;
if (!isSeen) // isSeen lets me know the status of the Form-
Visible or not
{
myForm.displayForm(); //sets Visible to true
isSeen = true;
}
else
{
myForm.hideForm(); //sets Visible to false
isSeen = false;
}
}
}




Nicholas Paldino said:
Doc,

Can you show an example where this happens? When setting the Visible
property to false, then back to true (I have a timer make the form
visible again) it comes back in the same place.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Doc John" <no email> wrote in message
I have an MDI container with a child Form which will be visible
according to certain events. The problem is that when I set the property
Visible to False and then back to True, the Form will be in another
location, or it will be maximized.

Why does the child Form change its location when the Visible propery is
set true (after being set to False)? Why doesn't it stay with the same
Size and the same Location?

Thanks.

 
D

Doc John

StartupPosition has to be set to Manual.

Nicholas Paldino said:
Well, that is by no means a complete example. The displayForm and
hideForm methods are doing something, and I imagine that the code that is
moving the forms is located somewhere in those methods.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Doc John said:
Thanks for the post.

I have an MDI Container and a TabControl docked to the left (similar to
the Outlook interface). This tab control has two buttons: One that
instantiates the child Form frm_listBrowse, and another button
(button_visible) that calls a procedure in frm_listBrowse that sets the
Visible property to false.
Assuming that I've already created an instance of frm_listBrowse, this is
the code in button_invisible in my tabcontrol:

Form[] childForm = this.MdiChildren;
Form_base myForm = new Form_base(); //all Forms inherit from Form_base
which includes method hideForm() and displayForm().
Form f;

for (int i = 0; i < childForm.Length; i++)
{
if (childForm.Name == "frm_listBrowse")
{
f = (Form)childForm;
myForm = f as frm_listBrowse;
if (!isSeen) // isSeen lets me know the status of the Form-
Visible or not
{
myForm.displayForm(); //sets Visible to true
isSeen = true;
}
else
{
myForm.hideForm(); //sets Visible to false
isSeen = false;
}
}
}




Nicholas Paldino said:
Doc,

Can you show an example where this happens? When setting the Visible
property to false, then back to true (I have a timer make the form
visible again) it comes back in the same place.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Doc John" <no email> wrote in message
I have an MDI container with a child Form which will be visible
according to certain events. The problem is that when I set the property
Visible to False and then back to True, the Form will be in another
location, or it will be maximized.

Why does the child Form change its location when the Visible propery is
set true (after being set to False)? Why doesn't it stay with the same
Size and the same Location?

Thanks.

 
L

Linda Liu [MSFT]

Hi Doc,
It moves about 1/2-inch to the bottom and to the right. After about five
clicks, it'll move back to the top.

I performed a test changing the Visible property of an MDI child form. I
see the same thing as you decribed in the above sentence. This is because
the MDI parent controls the location of its MDI child form when the MDI
child is shown in it.

In my test, I don't reproduce that the MDI child form becomes maximized
when its Visible property is set to true (originally it's false). Maybe the
WindowState property of the MDI child form is changed somewhere else in
your application.

As you have pointed out, we could set the MDI child form's StartupPosition
property to Manual, so that the MDI parent won't influence the location of
its MDI child form when the MDI child form is shown.

If you have any concern, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

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

Chris Dunaway

for (int i = 0; i < childForm.Length; i++)
{
if (childForm.Name == "frm_listBrowse")
{
f = (Form)childForm;
myForm = f as frm_listBrowse;
if (!isSeen) // isSeen lets me know the status of the Form- Visible
or not
{
myForm.displayForm(); //sets Visible to true
isSeen = true;
}
else
{
myForm.hideForm(); //sets Visible to false
isSeen = false;
}
}
}


I am curious, correct me if I'm wrong but this method seems to set the
child form to visible if it is not visible and to hide if it is. Is
that correct?

Why have a method (displayform, hideForm) that sets the visible
property? Why not just use:

myForm.Visible = true;

and instead of using your isSeen variable, why not just use:

if (!myForm.Visible)

and finally, if you're just toggling the visibility of the form, why
use a big if statement instead of something like this:

myForm.Visible = !myForm.Visible;

Just wondering.

Chris
 
L

Linda Liu [MSFT]

Hi Doc,

How about the problem now?

If you still need our further assistance, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 

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