Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

detecting control visibility before form shows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob - 01 Oct 2004 19:24 GMT
Is it possible to tell if a control would be visible (or hidden) before
making its parent form visible?

Bob
Kamaluokeakua - 01 Oct 2004 21:23 GMT
Bob,

Nothing will show Visible until the form itself has shown itself.  You can
test this by setting up two forms.  Form1 has just a button called button1.  
Form2 has a textBox1 and a button1.  The button was created first and holds
the position of 0 in the Form.Components array.  textBox1 will hold the value
of 1 in the Form.Components array.  By setting the Visible to true on the
textBox1 control and placing the following code in the button1_Click event
you will always get textBox1 is NOT visible.

private void button1_Click(object sender, System.EventArgs e)
{
   Form2 f2 = new Form2();

   switch (f2.Controls[1].Visible)
   {
       case true:
           MessageBox.Show("textBox1 is visible", "Form1");
           break;
       case false:
    MessageBox.Show("textBox1 is NOT visible", "Form1");
    break;
   }
   f2.Show();
}

If you are looking to set it when the form loads based on roles and security
your best bet is being able to set a variable on the form that tells the Load
event what you want on and off on the form based on the users credentials.  
This is of course assuming that is the direction you are going with this.

Regards,

Kamaluokeakua

> Is it possible to tell if a control would be visible (or hidden) before
> making its parent form visible?
>
> Bob
Bob - 03 Oct 2004 21:24 GMT
Nope, not the direction I was going.

Let's see... it will be easier for me to start with the example I'm working
on at the moment. Picture a form where a user can select from a list of
items. When this list's selected item changes, the containing form handles
this as an event and notifies many other controls - all of which are on
various tab pages - that the selected item has changed. These controls, on
being notified, need to reload data based on this new parameter. As you
might guess, in the interest of making forms of such design more efficient,
I cause these data-loading controls to check first to see if they're
available to the user in the first place. If, for instance, a control finds
an unselected tab page in its chain of parents, it can set a local
'LoadDeferred' bit, and defer loading until OnVisibleChanged.

Simply checking for unselected tab pages in a control's parent chain does do
the trick for a lot of cases. But I want to solve for the general case; if
the user isn't going to see the control, I want it to hold off loading data
until it becomes visible. Using the Visible property is what I would want to
use, but this doesn't work if I want to make a selection (load a saved
state) before the form is even shown. I can't use an 'is this control
currently visible' property, I need an independent 'was this control told to
be visible in this parent' property.

Does that make any sense?

Anyway, there are hacks around this problem, and I don't exactly _have_ to
load a form's saved state before it becomes visible. But that looks messier,
causes a double-loading of data, and I *know* that hierarchal Visible
information is available somewhere, because the WinForms uses it to give you
an end result. I just need to know how to get at it. Perhaps there's an API
call?

Bob

> Nothing will show Visible until the form itself has shown itself.  You can
> test this by setting up two forms.  Form1 has just a button called button1.
[quoted text clipped - 24 lines]
> event what you want on and off on the form based on the users credentials.
> This is of course assuming that is the direction you are going with this.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.