UserControl: Hide Children

  • Thread starter Thread starter Michael Maes
  • Start date Start date
M

Michael Maes

Hi,

I have a UserControl with some "Children" (e.g. one ComboBox & one Label).

I add the UserControl on a Form.
If I perform a recursive scan through that Form's Control-Collection the ..HasChildren-Method scans the Controls within the UserControl.

This is a behavior I want to ommit.

* Is there a way to hide the Controls contained within a UserControl so that UserControl.HasChildren will always return False? *

TIA,

Michael
 
Hi,

I can't think of a way to override the behavior of this property,
do you mean you want to recursive scan from the From but want to skip step
into on certain UserControl type?

Maybe you could add a user-defined attribute on the definiation of the
usercontrol and check the value of this attribute in your recursive
algorithm.

another approach maybe derive from the UserControl class and define an
abstract method on to enumerate it's children,
then derive your user control from this class and implement the enumeration
in each classes, so that we could divide the recursive scan into one method
call, and every class will execute based on it's defined behavior.

Feel free to reply this thread if you have anything unclear about it.

Have a nice day!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Hi Yin-Shen,

Thanks for your reply.
It's a pitty the Framework hasn't got a "standard" method to achieve this....

Anyway: thanks for your directives. It is indeed quite simple to achieve with a Custom Attribute.
Here's how I handled it:

<DebuggerStepThrough(), AttributeUsage(AttributeTargets.Class)> _
Public Class SkipRecursiveScanOnChildren
Inherits Attribute
End Class

***************
<SkipRecursiveScanOnChildren()> _
Public Class UIButtonComboBox
Inherits System.Windows.Forms.UserControl
................
***************
If [Control].HasChildren And Not SkipChildren([Control]) Then
......
End If

Private Function SkipChildren(ByVal [Control] As System.Windows.Forms.Control) As Boolean
Dim att() As Object = _
[Control].GetType.GetCustomAttributes(GetType(SkipRecursiveScanOnChildren), True)
Return (UBound(att) > -1)
End Function

Best regards,

Michael
 
Sorry about the long delay, I just saw your post.

What I do is, while iterating through the hierarchy, when I am looking at a
control, say

if typename(somecontrol.parent ) = "UserControl" then
'do something, ignore it, whatever
Else
'do something else
Endif


Hi,

I have a UserControl with some "Children" (e.g. one ComboBox & one Label).

I add the UserControl on a Form.
If I perform a recursive scan through that Form's Control-Collection the
..HasChildren-Method scans the Controls within the UserControl.

This is a behavior I want to ommit.

* Is there a way to hide the Controls contained within a UserControl so that
UserControl.HasChildren will always return False? *

TIA,

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top