Hide() not working correctly

P

Paul R

Hi,

My application should only ever display one form at a
time. To achieve this I navigate between forms using the
following logic:

From formA to formB -

formB.Show()
formA.Hide()

This is fine and works OK except in the following case:

If the form to be displayed (formB) takes a few seconds
to load, and in that time the user clicks on the current
form (formA) IN THE TASKBAR, the system displays formB
but does not hide formA. Both of the forms are displayed
in the taskbar, and both can be selected by clicking or
Alt+Tabbing.

I have put some debug in, and the form being hidden does
get the message, and it even thinks it has been hidden
(if your query the Visible property it is set to False,
even though it clearly IS visible).

This is becoming a real pain and I have not yet found a
suitab;e workaround. Can anyone help?

Thanks for any help.
 
C

Chris Dunaway

If the form to be displayed (formB) takes a few seconds
to load, and in that time the user clicks on the current
form (formA) IN THE TASKBAR, the system displays formB

A work around is to set the form's ShowInTaskbar property to False.
Perhaps that would help.
 
C

Carol Torkko

Hi,
The reason why switching the Hide and Show commands may
work as I indicated earlier is because you are using the
Show method to open FormB and that means you are opening a
modeless form, which means that in applications when you
have multiple forms opened as modeless, the user can
switch between the forms interactively. For this to work,
the user will not receive focus to FormB until the entire
routine in which you are showing FormB is completely
executed. It should be basically the last command in your
routine.

If you are looking to control the user to use FormB and
not return to FormA until FormB is done and you want FormA
hidden while FormB is opened then do the following code:

FormA.Hide
FormB.ShowDialog
FormA.Show

This means you are using a modal form. FormA will be
hidden immediately, FormB will be shown immediately. When
FormB is closed or hidden, then the next command,
FormA.Show will execute and show FormA.

I hope this helps. My email address has only 2 "k"s in
it. Carol

In general, it is not recommended to completely control
users on use of forms, because a lot of users want more
flexibility to switch between forms.
 
P

Paul R

Thanks Chris,

The workaround you suggest does seem to work, though it causes a nasty
double re-draw for some reason!! Any ideas on why or how to get around
that?

Thanks again.
 
P

Paul R

Hi Carol,

Thanks for replying. Switching the show/hide calls causes the screen to go
blank (with no form displayed) until the form being shown completes any
initialisation code. The time taken to actually refresh some of my forms
can be a second or two, and the flicker appears too great.

Thanks for the suggestion!
 
C

Carol Torkko

Hi,
There is most of the time more than one way to accomplish
a task. I have some questions on your project:
1. Is memory an issue?
2. Does FormB appear the same everytime it is loaded?
3. Are you working with graphic images?
4. Are you working with connections to servers?
5. What is causing FormB to take some time to load?

Where I am headed with these questions is to possibly
determine a way to quicken the process. It is
exasperating to the user no matter how long they have to
wait regardless of what is showing on the screen (nothing,
etc.) at the time.

Depending on what is causing the time delay, it may be
possible to take care some of the issues early on a one
time basis while the project is running.

Carol
 
Y

Ying-Shen Yu[MSFT]

Hi Paul,
As you said, formB.Show need do a lot of initialization which will take a
second or two, in my mind, this might block the message loop, so the
WM_ACTIVATE/WM_DEACTIVATE message will be blocked until the current event
handler return.
So actually Hide is executed before processing WM_ACTIVATE message, while
the result of activating a hidden window is not defined. you may call
Application.DoEvents before calling formA.Hide this will give chance to
Framework to handle WM_ACTIVATE before calling Hide. Or try inserting some
DoEvents call in your On_Load event handler of formB, this will make your
application more interactively.

Does this solve your problem?
Be free to post on this group, if you still have problem on this issue.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| Content-Class: urn:content-classes:message
| From: "Paul R" <[email protected]>
| Sender: "Paul R" <[email protected]>
| Subject: Hide() not working correctly
| Date: Mon, 27 Oct 2003 03:43:02 -0800
| Lines: 31
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOcf3p4Ojh9L9W0TaOqqGcEkHxb5Q==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:55283
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Hi,
|
| My application should only ever display one form at a
| time. To achieve this I navigate between forms using the
| following logic:
|
| From formA to formB -
|
| formB.Show()
| formA.Hide()
|
| This is fine and works OK except in the following case:
|
| If the form to be displayed (formB) takes a few seconds
| to load, and in that time the user clicks on the current
| form (formA) IN THE TASKBAR, the system displays formB
| but does not hide formA. Both of the forms are displayed
| in the taskbar, and both can be selected by clicking or
| Alt+Tabbing.
|
| I have put some debug in, and the form being hidden does
| get the message, and it even thinks it has been hidden
| (if your query the Visible property it is set to False,
| even though it clearly IS visible).
|
| This is becoming a real pain and I have not yet found a
| suitab;e workaround. Can anyone help?
|
| Thanks for any help.
|
|
|
 
P

PaulR

Hi,

Thanks for the reply.

I had previously tried inserting a call to
Application.DoEvents() before the call to hide, but this
had another adverse effect...

Our application uses the keyboard to navigate. If the
uses quickly navigates from FormA to FormB and back to
FormA then both of the forms end up being hidden!

Do you have any other suggestions!?
-----Original Message-----
Hi Paul,
As you said, formB.Show need do a lot of initialization which will take a
second or two, in my mind, this might block the message loop, so the
WM_ACTIVATE/WM_DEACTIVATE message will be blocked until the current event
handler return.
So actually Hide is executed before processing WM_ACTIVATE message, while
the result of activating a hidden window is not defined. you may call
Application.DoEvents before calling formA.Hide this will give chance to
Framework to handle WM_ACTIVATE before calling Hide. Or try inserting some
DoEvents call in your On_Load event handler of formB, this will make your
application more interactively.

Does this solve your problem?
Be free to post on this group, if you still have problem on this issue.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| Content-Class: urn:content-classes:message
| From: "Paul R" <[email protected]>
| Sender: "Paul R" <[email protected]>
| Subject: Hide() not working correctly
| Date: Mon, 27 Oct 2003 03:43:02 -0800
| Lines: 31
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOcf3p4Ojh9L9W0TaOqqGcEkHxb5Q==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:55283
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Hi,
|
| My application should only ever display one form at a
| time. To achieve this I navigate between forms using the
| following logic:
|
| From formA to formB -
|
| formB.Show()
| formA.Hide()
|
| This is fine and works OK except in the following case:
|
| If the form to be displayed (formB) takes a few seconds
| to load, and in that time the user clicks on the current
| form (formA) IN THE TASKBAR, the system displays formB
| but does not hide formA. Both of the forms are displayed
| in the taskbar, and both can be selected by clicking or
| Alt+Tabbing.
|
| I have put some debug in, and the form being hidden does
| get the message, and it even thinks it has been hidden
| (if your query the Visible property it is set to False,
| even though it clearly IS visible).
|
| This is becoming a real pain and I have not yet found a
| suitab;e workaround. Can anyone help?
|
| Thanks for any help.
|
|
|

.
 
P

Paul R

Hi Carol,

1. Memory not really an issue
2. Yes FormB needs to appear in the same state
3. no graphic
4. Using ADO.NET for data access
5. Sometimes FormB may need to load a new dataview, which
is what can take up to 2 seconds.

I understand your point, I am looking at ways to spped up
the process.
 
C

Carol Torkko

Hi,
I'm sorry if I keep bugging you with these questions, but
in the end you may end up with the solution you are
looking for. This dataview:
1. Is the data brought in the server at the time FormB is
loaded or is the data already contained in a dataset?
2. If you are using a dataset do you refresh the data and
if so how often?
3. If you are going to the server everytime, are you
bringing in all the data into the dataset and then
creating a view from that or are you creating a view on
the server and bringing in only the data from the view?

There can be a significant difference in performance among
these options. Carol
 
Y

Ying-Shen Yu[MSFT]

Hi Paul,
Thanks for you reply,
You said your application uses keyboard to navigate, however I'm not clear
about
how you implement this navigate.Is it like the following style?
void key1down_event(...)
{
form2.show();
Application.DoEvents();
form1.hide();
}
void key2down_event(....)
{
form1.show();
Application.DoEvents();
form2.hide();
}
If yes, it might cause the problem, to my understanding, each event handler
should be executed as a unit of work, however, DoEvents will let the
key2down executes inside the key1down event handler. You may try adding a
flag and checking it in both event_handlers before doing the real things,
such as:
void key1down_event(...)
{
if( ! InFormSwitching)
{
InFormSwitching = true;
form1.show();
//the key2down_event might be executed here.
//adding the flag will let key2down event handler bypass the actual code
Application.DoEvents();
form2.hide();
InFormSwitching = false;
}
}

Does it solved your problem?
If you have anything unclear about it, please be free to reply it on this
group.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 
Y

Ying-Shen Yu[MSFT]

Hi Paul,
You haven't updated this issue for days, How about your problem now?
If you still have problem on it, please don't hesitate to reply to this
group.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 

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