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 ?
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?
Rating is a way of saying thank you. Don't forget to rate always!
'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.
Last edited by VBDT; Dec 10th, 2006 at 06:40 PM.
Rating is a way of saying thank you. Don't forget to rate always!
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.
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 ?????
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.
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 !!!
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.
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.
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.