Results 1 to 18 of 18

Thread: [2005] Hide control subcontrols

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Question [2005] Hide control subcontrols

    Hello ,

    i have create my custom form.

    in that form i use a lot of controls like labels , panels , buttons etc.

    when i inherit from that form in a project i see in propertis not only the form properties but the properties of all the controls i use in my custom from .

    Can i hide the contols i use in my custom from from properties ?

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Hide control subcontrols

    have you tried it?

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Question Re: [2005] Hide control subcontrols

    Quote Originally Posted by VBDT
    have you tried it?

    what to try ???

  4. #4
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Hide control subcontrols

    you say:
    when i inherit from that form in a project i see in propertis not only the form properties but the properties of all the controls i use in my custom from .
    have you tried to set the visible properties of the controls to false?

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Question Re: [2005] Hide control subcontrols

    Quote Originally Posted by VBDT
    you say:

    have you tried to set the visible properties of the controls to false?
    how i do that ???

  6. #6
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Hide control subcontrols

    Can you post your project?

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Re: [2005] Hide control subcontrols

    here is my project

    Look at form1 you can each control included in cpmform
    Attached Files Attached Files

  8. #8
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Hide control subcontrols

    which controls do you want to hide? all of them? or some particulare ones?

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Re: [2005] Hide control subcontrols

    Quote Originally Posted by VBDT
    which controls do you want to hide? all of them? or some particulare ones?

    all of them

  10. #10
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [2005] Hide control subcontrols

    VB Code:
    1. 'Hides the control with the specified control-name.
    2.         For Each cont As Control In Me.Controls
    3.             If cont.Name = "the name of the control" Then
    4.                 cont.Visible = False
    5.             End If
    6.         Next
    7.  
    8.         'Hides all Lable controls on the form.
    9.         For Each cont As Control In Me.Controls
    10.             If cont.GetType.Name = "Lable" Then
    11.                 cont.Visible = False
    12.             End If
    13.         Next
    14.         'Hides all the controls.
    15.         For Each cont As Control In Me.Controls
    16.             cont.Visible = False
    17.         Next
    You can set the visible properties of the controls by setting it to true the same way.
    Not these does not hide controls that are in a container! These are fine for your project since you don't have controls in a container.

  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Exclamation Re: [2005] Hide control subcontrols

    Thanks for your help but there is a problem !!!!

    I don't want to make the controls of cmpForm unvisible

    i want to hide the properties of the controls when i inherit from cmpForm

    example: in solution , in test project, In form1 u can see the properties for each control used in cmpForm .

    that's are i want to hide !!!

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Hide control subcontrols

    The problem is that you've declared all your child controls as Public. They should be declared Private. You then declare properties of the UserControl itself, e.g.
    VB Code:
    1. Public Property SelectedItem() As Object
    2.     Get
    3.         Return Me.ComboBox1.SelectedItem
    4.     End Get
    5.     Set(ByVal value As Object)
    6.         Me.ComboBox.SelectedItem = value
    7.     End Set
    8. End Property
    Now the form will set the SelectedItem property of your UserControl and this will set the SelectedItem property of the ComboBox internally, but because the ComboBox has been declared Private it cannot be accessed directly from outside the UserControl.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Re: [2005] Hide control subcontrols

    Quote Originally Posted by jmcilhinney
    The problem is that you've declared all your child controls as Public. They should be declared Private. You then declare properties of the UserControl itself, e.g.
    VB Code:
    1. Public Property SelectedItem() As Object
    2.     Get
    3.         Return Me.ComboBox1.SelectedItem
    4.     End Get
    5.     Set(ByVal value As Object)
    6.         Me.ComboBox.SelectedItem = value
    7.     End Set
    8. End Property
    Now the form will set the SelectedItem property of your UserControl and this will set the SelectedItem property of the ComboBox internally, but because the ComboBox has been declared Private it cannot be accessed directly from outside the UserControl.
    how i declare the contols into cmpform as private ?????

  14. #14
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Hide control subcontrols

    You open your UserControl in the designer, select each control and change it's Modifiers property to Private.

    Note that the default access level in VB is Friend, not Public as I said previously. This is aprt of VB's effort to be easier to use for beginners because it means that you can set properties of the controls directly instead of having to declare extra properties in the UserControl. That leads to bad programming habits so all controls should be declared Private, as is the default in C#.

    You will also want to change the access level of all controls, which is a very easy operation. Select your UserControl in the designer, press Ctrl+A (the standard "Select All" shortcut) to select every control and component, go to the Properties window, right click the Modifiers property and select "Reset". Done.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  15. #15

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Re: [2005] Hide control subcontrols

    Quote Originally Posted by jmcilhinney
    You open your UserControl in the designer, select each control and change it's Modifiers property to Private.

    Note that the default access level in VB is Friend, not Public as I said previously. This is aprt of VB's effort to be easier to use for beginners because it means that you can set properties of the controls directly instead of having to declare extra properties in the UserControl. That leads to bad programming habits so all controls should be declared Private, as is the default in C#.

    You will also want to change the access level of all controls, which is a very easy operation. Select your UserControl in the designer, press Ctrl+A (the standard "Select All" shortcut) to select every control and component, go to the Properties window, right click the Modifiers property and select "Reset". Done.
    if u see in the project i attach to previous post all the modifiers are Private in cmpForm !!!

  16. #16
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Hide control subcontrols

    I didn't say in the form. I said in the UserControl. Open the UserControl in the designer and set the access levels of its child controls. Then when you use that UserControl on a form the private controls will not be able to be accessed directly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  17. #17

    Thread Starter
    Member
    Join Date
    Aug 2006
    Location
    Moscato , Athens , Greece
    Posts
    60

    Re: [2005] Hide control subcontrols

    Quote Originally Posted by jmcilhinney
    I didn't say in the form. I said in the UserControl. Open the UserControl in the designer and set the access levels of its child controls. Then when you use that UserControl on a form the private controls will not be able to be accessed directly.
    the cmpForm is the contol and there all contols are private.

    open the attached solution and u see

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Hide control subcontrols

    I'm not sure where I got the idea that you were creating a UserControl. I must have just made that up. I was under the impression that you were implying that when you used your UserControl ona form you were able to set the properties of the child control. Are you saying that the issue is that in the inherited form you can click on one of the private controls on the base form and all the properties are listed, although they are all read-only? If that's the issue then I'm afraid that you'll have to live with it as it's a function of visual inheritance. You can't see those properties in code but they are always going to be visible in the designer. I'm not aware of any way to avoid that.

    If that's not your issue then please explain further.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width