Help! Tab Pages and the Tab Control

J

joey.powell

Hello,

I have an app that uses a tab control with several tab pages.
Sometimes some of the processing initiated on one of the tab pages
gets busy doing stuff that is farmed out to worker threads. I have to
be able to prevent the tab page from changing (prevent users selecting
other tabs) while this is going on.

I already have a variable to track the status of this (i.e. "bool
IsBusy"), but I cannot figure out now to "freeze" the tab pages when
"IsBusy" is true. The idea is to freeze them while the processing is
going on and then unfreeze them once it has completed.

So far I have tried setting the "CanSelect" properties for each of the
other tab pages, but they are read-only. Also, each tab page does not
appear to have an "Enabled" property like most other controls. That
would make things a lot easier.

Gusy, how can I get this to work?
 
J

Joe Cool

Hello,

I have an app that uses a tab control with several tab pages.
Sometimes some of the processing initiated on one of the tab pages
gets busy doing stuff that is farmed out to worker threads. I have to
be able to prevent the tab page from changing (prevent users selecting
other tabs) while this is going on.

I already have a variable to track the status of this (i.e. "bool
IsBusy"), but I cannot figure out now to "freeze" the tab pages when
"IsBusy" is true. The idea is to freeze them while the processing is
going on and then unfreeze them once it has completed.

So far I have tried setting the "CanSelect" properties for each of the
other tab pages, but they are read-only. Also, each tab page does not
appear to have an "Enabled" property like most other controls. That
would make things a lot easier.

Gusy, how can I get this to work?

There are several events that get fired when you click on another tab.
You may be able to accomplish your task by checking you status
variable in one of these. I would suggest the Validating event. You
will also need a variable that points to the current tab, so you know
where to go back to if needed.
 
R

Richard Carpenter

Hello,

I have an app that uses a tab control with several tab pages.
Sometimes some of the processing initiated on one of the tab pages
gets busy doing stuff that is farmed out to worker threads. I have to
be able to prevent the tab page from changing (prevent users selecting
other tabs) while this is going on.

Is there a reason you're using worker threads? If the processing occurred in
the same thread as the calling function, wouldn't that take care of the
problem? If you're firing off *multiple* processes, that would explain it.
In that case, perhaps a check on the process status in a while loop?
 
R

Richard Carpenter

Hello,

I have an app that uses a tab control with several tab pages.
Sometimes some of the processing initiated on one of the tab pages
gets busy doing stuff that is farmed out to worker threads. I have to
be able to prevent the tab page from changing (prevent users selecting
other tabs) while this is going on.

Is there a reason you're using worker threads? If the processing occurred in
the same thread as the calling function, wouldn't that take care of the
problem? If you're firing off *multiple* processes, that would explain it.
In that case, perhaps a check on the process status in a while loop?
 
J

John B

Hello,

I have an app that uses a tab control with several tab pages.
Sometimes some of the processing initiated on one of the tab pages
gets busy doing stuff that is farmed out to worker threads. I have to
be able to prevent the tab page from changing (prevent users selecting
other tabs) while this is going on.

I already have a variable to track the status of this (i.e. "bool
IsBusy"), but I cannot figure out now to "freeze" the tab pages when
"IsBusy" is true. The idea is to freeze them while the processing is
going on and then unfreeze them once it has completed.

So far I have tried setting the "CanSelect" properties for each of the
other tab pages, but they are read-only. Also, each tab page does not
appear to have an "Enabled" property like most other controls. That
would make things a lot easier.

Gusy, how can I get this to work?

Handle the Selecting event and set e.Cancel to IsBusy

ie
void tab_Selecting(object sender, TabControlCancelEventArgs e)
{
e.Cancel = IsBusy;
}

JB
 
M

mgsram

Note that if you use this approach, be sure to provide the user with some
feedback as to _why_ you've canceled the tab change. For example,
displaying an alert.

That's one advantage of simply disabling the control: it becomes
immediately apparent to the user that the control isn't going to accept
user input. Other alternatives are viable though, as long as the user is
always presented with clear information about why they aren't able to
change tabs in the control.

Pete

Disabling the tab control OR canceling the tab change _alone_ can lead
to confusion to the user due to inactivity, especially if the wait
time is longer. I think if the wait time is in the order of few
seconds, it would be nice to have a decent progress bar providing well
defined feedback. We used a threshold of 5 seconds for displaying a
progress bar.
 
J

joey.powell

Disabling the control is not mutually exclusive with providing progress  
feedback.  I agree that progress feedback is desirable _as well_, and  
never intended anyone to take my suggestion to mean otherwise.  I'm sorry  
if I didn't make that clear enough.

Ignoring the issue of progress feedback though, disabling the control  
provides the user with a clear indication that the UI will not respond at  
the moment.  That's a lot different from a control that looks ready to  
respond but ignores your input without any feedback at all.

Pete

We are already using a progress bar and status text to provide visual
feedback. And this is another reason why we are using worker threads -
we would see "white out," and it would get really ugly otherwise.

As for disabling the entire tab control, well that is not an option.
This is because the associated progress bar, status text, and a cancel
button are containted within it.

I agree with John B, wow a Selecting event with an EventArg e with a
cancel option would be a great solution. And that's what I went
looking for first. Unfortunately these options do not exist with the
tab control (at least not in .net 3.5)!

And Peter, I understand about the "Help in the subject" thing. You're
right.

Any other suggestions?
 
J

joey.powell

We are already using a progress bar and status text to provide visual
feedback. And this is another reason why we are using worker threads -
we would see "white out," and it would get really ugly otherwise.

As for disabling the entire tab control, well that is not an option.
This is because the associated progress bar, status text, and a cancel
button are containted within it.

I agree with John B, wow a Selecting event with an EventArg e with a
cancel option would be a great solution. And that's what I went
looking for first. Unfortunately these options do not exist with the
tab control (at least not in .net 3.5)!

And Peter, I understand about the "Help in the subject" thing. You're
right.

Any other suggestions?- Hide quoted text -

- Show quoted text -

OK OK not sure what was going on earlier, but I found a "Selecting"
event. I'm checking into that now...
 
I

Ignacio Machin ( .NET/ C# MVP )

Note that if you use this approach, be sure to provide the user with some  
feedback as to _why_ you've canceled the tab change.  For example,  
displaying an alert.

That's one advantage of simply disabling the control: it becomes  
immediately apparent to the user that the control isn't going to accept  
user input.  Other alternatives are viable though, as long as the user is  
always presented with clear information about why they aren't able to  
change tabs in the control.

Pete

Hi,

I think that the best solution is your proposed modal dialog
 

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