[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 ?
Re: [2005] Hide control subcontrols
Re: [2005] Hide control subcontrols
Quote:
Originally Posted by VBDT
have you tried it?
what to try ???
Re: [2005] Hide control subcontrols
you say:
Quote:
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?
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 ???
Re: [2005] Hide control subcontrols
Can you post your project?
1 Attachment(s)
Re: [2005] Hide control subcontrols
here is my project
Look at form1 you can each control included in cpmform
Re: [2005] Hide control subcontrols
which controls do you want to hide? all of them? or some particulare ones?
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
Re: [2005] Hide control subcontrols
VB Code:
'Hides the control with the specified control-name.
For Each cont As Control In Me.Controls
If cont.Name = "the name of the control" Then
cont.Visible = False
End If
Next
'Hides all Lable controls on the form.
For Each cont As Control In Me.Controls
If cont.GetType.Name = "Lable" Then
cont.Visible = False
End If
Next
'Hides all the controls.
For Each cont As Control In Me.Controls
cont.Visible = False
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.
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 !!!
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:
Public Property SelectedItem() As Object
Get
Return Me.ComboBox1.SelectedItem
End Get
Set(ByVal value As Object)
Me.ComboBox.SelectedItem = value
End Set
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.
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:
Public Property SelectedItem() As Object
Get
Return Me.ComboBox1.SelectedItem
End Get
Set(ByVal value As Object)
Me.ComboBox.SelectedItem = value
End Set
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 ?????
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.
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 !!!
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.
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
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.