How to get all the controls on form and non-form?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?WVhR?=

    #1

    How to get all the controls on form and non-form?

    Me.Controls can get all the controls on the form, but i want to get all the
    controls include non-from controls, for example ToolTip, ContextMenuStri p...
    Thank you
  • kimiraikkonen

    #2
    Re: How to get all the controls on form and non-form?

    On Nov 10, 6:16 am, YXQ <Y...@discussio ns.microsoft.co mwrote:
     Me.Controls can get all the controls on the form, but i want to get all the
    controls include non-from controls, for example ToolTip, ContextMenuStri p....
    Thank you
    I think because they don't inherit Control class, as a result they're
    not identified as controls.
    See which classes/interfaces they implement. For example ToolTip class
    inherits Component class, not control:
    http://msdn.microsoft.com/en-us/libr...s.tooltip.aspx

    So, you can loop Components to get them as follows:

    For Each comp As System.Componen tModel.Componen t _
    In Me.components.C omponents
    ' Tooltip and ContextMenuStri p will be found here
    Next

    Hope this helps,

    Onur Güzel

    Comment

    • yxq

      #3
      Re: How to get all the controls on form and non-form?

      You are a expert, thank you, but if this code is in moulde sub, for example:

      Public sub AAA(Byval FormName as Form)
      For Each comp As System.Componen tModel.Componen t In
      FormName.compon ents.Components
      ' Tooltip and ContextMenuStri p will be found here
      Next
      End Sub

      The code above will not work if replace "Me" with "FormName", why?
      Thank you


      "kimiraikko nen" <kimiraikkonen8 5@gmail.com>
      ??????:f2c9053a-4fc0-4ac3-b23e-f09df16cddac@g1 7g2000prg.googl egroups.com...
      On Nov 10, 6:16 am, YXQ <Y...@discussio ns.microsoft.co mwrote:
      Me.Controls can get all the controls on the form, but i want to get all
      the
      controls include non-from controls, for example ToolTip,
      ContextMenuStri p...
      Thank you
      I think because they don't inherit Control class, as a result they're
      not identified as controls.
      See which classes/interfaces they implement. For example ToolTip class
      inherits Component class, not control:
      http://msdn.microsoft.com/en-us/libr...s.tooltip.aspx

      So, you can loop Components to get them as follows:

      For Each comp As System.Componen tModel.Componen t _
      In Me.components.C omponents
      ' Tooltip and ContextMenuStri p will be found here
      Next

      Hope this helps,

      Onur Güzel


      Comment

      • Jack Jackson

        #4
        Re: How to get all the controls on form and non-form?

        Because the 'components' field in a form is Private, therefore it is
        visible only from within the form.

        On Tue, 11 Nov 2008 06:21:10 +0800, "yxq" <gayxq@163.netw rote:
        >You are a expert, thank you, but if this code is in moulde sub, for example:
        >
        >Public sub AAA(Byval FormName as Form)
        For Each comp As System.Componen tModel.Componen t In
        >FormName.compo nents.Component s
        ' Tooltip and ContextMenuStri p will be found here
        Next
        >End Sub
        >
        >The code above will not work if replace "Me" with "FormName", why?
        >Thank you
        >
        >
        >"kimiraikkonen " <kimiraikkonen8 5@gmail.com>
        >??????:f2c9053 a-4fc0-4ac3-b23e-f09df16cddac@g1 7g2000prg.googl egroups.com...
        >On Nov 10, 6:16 am, YXQ <Y...@discussio ns.microsoft.co mwrote:
        >Me.Controls can get all the controls on the form, but i want to get all
        >the
        >controls include non-from controls, for example ToolTip,
        >ContextMenuStr ip...
        >Thank you
        >
        >I think because they don't inherit Control class, as a result they're
        >not identified as controls.
        >See which classes/interfaces they implement. For example ToolTip class
        >inherits Component class, not control:
        >http://msdn.microsoft.com/en-us/libr...s.tooltip.aspx
        >
        >So, you can loop Components to get them as follows:
        >
        >For Each comp As System.Componen tModel.Componen t _
        >In Me.components.C omponents
        >' Tooltip and ContextMenuStri p will be found here
        >Next
        >
        >Hope this helps,
        >
        >Onur Güzel
        >

        Comment

        • kimiraikkonen

          #5
          Re: How to get all the controls on form and non-form?

          On Nov 11, 12:21 am, "yxq" <ga...@163.netw rote:
          You are a expert, thank you, but if this code is in moulde sub, for example:
          >
          Public sub AAA(Byval FormName as Form)
              For Each comp As System.Componen tModel.Componen t In
          FormName.compon ents.Components
                  ' Tooltip and ContextMenuStri p will be found here
             Next
          End Sub
          >
          The code above will not work if replace "Me" with "FormName", why?
          Thank you
          >
          "kimiraikko nen" <kimiraikkone.. .@gmail.com>
          ??????:f2c9053a-4fc0-4ac3-b23e-f09df16cd...@g1 7g2000prg.googl egroups.com....
          On Nov 10, 6:16 am, YXQ <Y...@discussio ns.microsoft.co mwrote:
          >
          Me.Controls can get all the controls on the form, but i want to get all
          the
          controls include non-from controls, for example ToolTip,
          ContextMenuStri p...
          Thank you
          >
          I think because they don't inherit Control class, as a result they're
          not identified as controls.
          See which classes/interfaces they implement. For example ToolTip class
          inherits Component class, not control:http://msdn.microsoft.com/en-us/libr....forms.tooltip....
          >
          So, you can loop Components to get them as follows:
          >
          For Each comp As System.Componen tModel.Componen t _
          In Me.components.C omponents
          ' Tooltip and ContextMenuStri p will be found here
          Next
          >
          Hope this helps,
          >
          Onur Güzel
          Thanks for the feedback,

          For the problem, as Jack said, "components " variable supplied with
          Private access modifier within that form. To call through other form,
          you need to call the loop from other form using "Me".

          HTH,

          Onur Güzel

          Comment

          Working...