Winforms Question
-
hi all, I'm having a bit of an issue here and maybe one of you guys can help me out :-D. I'm looking for a way to return all COMPONENTS in a form during run-time, and i mean components including all controls , menu's, custom controls etc. As you all now a control is a component but a component is not a control. You will probably think that i'm somesort of idiot , but i'm not ;-) (at least i think i'm not), and i've tried every possible way to reach my goal: 1) tried to convert the form as container -> didn't work 2) adding the component that needs to perform above actions and using it's own container as componentcollection holder doesn't work, bcause the container returned is the component itself. 3) returning a menu's container -> doesn't work -> it always returns nothing batmike2000
-
hi all, I'm having a bit of an issue here and maybe one of you guys can help me out :-D. I'm looking for a way to return all COMPONENTS in a form during run-time, and i mean components including all controls , menu's, custom controls etc. As you all now a control is a component but a component is not a control. You will probably think that i'm somesort of idiot , but i'm not ;-) (at least i think i'm not), and i've tried every possible way to reach my goal: 1) tried to convert the form as container -> didn't work 2) adding the component that needs to perform above actions and using it's own container as componentcollection holder doesn't work, bcause the container returned is the component itself. 3) returning a menu's container -> doesn't work -> it always returns nothing batmike2000
-
There may be an easier answer than just digging up one for this. What's the final goal you're trying to reach?
Hi leeland, the final goal to achieve is a complete component and control iteration of a form to disable /enable them and make them in-/visible if demanded. But this in a dynamic way, cause i never can tell in advance what will be on the Form. kr. batmike2000
-
There may be an easier answer than just digging up one for this. What's the final goal you're trying to reach?
tnx Leeland, i've found the solution: i needed to use reflection
strFormName = param_Form.Name Dim param_Form_type As Type = param_Form.GetType() Dim compFields As FieldInfo() = param_Form_type.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic) For Each fiField As FieldInfo In compFields Dim strCtrl(1) As String strCtrl = ReturnCompName(fiField, param_Form) For Each dr As DataRow In myrs.Rows If strCtrl(0) = dr("SecAuthCtrl_Name") And fiField.FieldType.FullName = dr("SecAuthCtrl_Type") Then Select Case fiField.FieldType.FullName.ToLower Case "System.Windows.Forms.ToolBarButton".ToLower Dim cmp As ToolBarButton = DirectCast(fiField.GetValue(param_Form), ToolBarButton) cmp.Enabled = dr("SecAuthorized_Enabled") cmp.Visible = dr("SecAuthorized_Visible") Case "System.Windows.Forms.MenuItem".ToLower Dim cmp As MenuItem = DirectCast(fiField.GetValue(param_Form), MenuItem) cmp.Enabled = dr("SecAuthorized_Enabled") cmp.Visible = dr("SecAuthorized_Visible") Case Else End Select End If Next Next
this works now, tnx for your effort batmike2000