?
Solved

VB.net - find if a control is visible or not

Posted on 2007-04-10
6
Medium Priority
?
1,120 Views
Last Modified: 2009-07-29
I have a tab control with multiple tab pages.

I want to check if controls are visible on tab pages.  This works OK if I'm on the tab page that has the control I want to check is visible.
An example:

TabPage1 - has a control called Panel1. Panel1 is set to be visible/invisible by the program
TabPage2 - other stuff
TabPage3 - other stuff

If I am on TabPage2 or 3, and check if Panel1 on TabPage1 is visible, it always returns false (even though the Panel might be visible if I switch to TabPage1)

Basically I need to know if the control e.g. Panel1 is visible whether or not I'm on TabPage1.

Is there a way to know if Panel1 WOULD BE visible when switching to TabPage1 (even though it's NEVER visible to user when on a TabPage other than TabPage1)


Thanks
0
Comment
Question by:rwallacej
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

by:rwallacej
ID: 18881284
there are lots of showing/hiding of panels on Tabpage1. I'd hope not to have to set a variable every time the panel is set from visible to invisible
0
 
LVL 10

Expert Comment

by:tpwells
ID: 18881419
You can loop through the controls on a tabpage and check their visible state to see if any are visible this way:

        Dim myTabPage As New TabPage
        Dim controlsVisible As Boolean = False
        For Each c As Control In myTabPage.Controls
            If c.Visible Then
                controlsVisible = True
            End If
        Next

        If controlsVisible Then
            'there are visible controls on the tab page
        End If
0
 
LVL 10

Expert Comment

by:tpwells
ID: 18881427
Leave off the line:
        Dim myTabPage As New TabPage

and replace myTabPage with the name of the tab page you are wanting to check in this line:
        For Each c As Control In myTabPage.Controls
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:rwallacej
ID: 18881522
this works....but only if myTabPage  is visible
I need to check if a control WILL BE visible if I were to switch to myTabPage if I am not already on it
0
 
LVL 34

Accepted Solution

by:
Sancler earned 1400 total points
ID: 18881653
I don't think you can do that.  Try this.  One form, a panel, a few controls WITHIN the panel, a button OUTSIDE the panel.  This code

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Panel1.Visible = Not Panel1.Visible
        Debug.WriteLine("Panel visible = " & Panel1.Visible.ToString)
        For Each ctl As Control In Panel1.Controls
            Debug.WriteLine(ctl.Name & " visible = " & ctl.Visible)
        Next
    End Sub

As you can see if you run that, the toggling of the container control's visibility also toggles the visibility of the contained controls.

Although the TabPage control has no (overt) .Visible property, there is one.  The (2005) documentation says, in the list of properties

>>
 Visible  This member is not meaningful for this control.
<<

but if you click on the Visible link the documents say

>>
TabPage.Visible Property

[...]

This property supports the .NET Framework infrastructure and is not intended to be used directly from your code
<<

And if you stick code like this

        For Each ctl As Control In TabControl1.Controls
            If TypeOf (ctl) Is TabPage Then
                Debug.WriteLine(ctl.Name & " visible = " & ctl.Visible.ToString)
            End If
        Next

in a tabcontrol's SelectedIndexChanged sub, you will see that .Visible is set to False for all except the currently selected TabPage.

Putting those two little experiments together ... ;-(

Roger
0
 
LVL 10

Assisted Solution

by:tpwells
tpwells earned 600 total points
ID: 18881717
Sancler is right the controls inherit their visible state from their parent unless specifically told to be non-visible the control will be visible when the parent is visible and have visible=false when the parent is not visible.
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question