Access to Components at runtime

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

Given a reference to a Form object, is there any way to ascertain whether
there is a ToolTip component (or indeed any component) attached to it, and
then to be able to manipulate that component ?
 
Given a reference to a Form object, is there any way to ascertain whether
there is a ToolTip component (or indeed any component) attached to it,
and
then to be able to manipulate that component ?

objForm is our Form object, then:

Dim objCtrl as Control
'
For Each objCtrl in objForm.Controls
If TypeOf(objCtrl) is RadioButton Then
Dim objRadio as RadioButton = objCtrl
Debug.WriteLine ("Found RadioButton, name " & objRadio.Name & " and it's
state is " & objRadio.Checked)
ElseIf [and go, go, go]
End If
Next

Got the idea?
 
You are talking about Controls, I am talking about Components - different
thing. A tooltip is not in the Controls collection, for example.

Maniaque |CIA| said:
Given a reference to a Form object, is there any way to ascertain whether
there is a ToolTip component (or indeed any component) attached to it,
and
then to be able to manipulate that component ?

objForm is our Form object, then:

Dim objCtrl as Control
'
For Each objCtrl in objForm.Controls
If TypeOf(objCtrl) is RadioButton Then
Dim objRadio as RadioButton = objCtrl
Debug.WriteLine ("Found RadioButton, name " & objRadio.Name & " and it's
state is " & objRadio.Checked)
ElseIf [and go, go, go]
End If
Next

Got the idea?
 
You must read the Site object of the Form which is of type ISite and get the Container property from there. The container has a property called Components which contains all components available on the form (including tooltips, datasets and so on). You will find that some components that derive from MarshalByValueComponent will raise an exception when you are trying to use GetType to see what type of component that is. In this case you must use the GetService method of the Site object and get a reference to a IReferenceService object. Using the IReferenceService you can get the names and types of the components without problems and you can actually even interact with them... Use the GetComponent, GetName or GetReference methods of the IReferenceService to do that

Sorry, I don't have an example here, but if you need i can get one at home..

regards
iulia
 
Thanks very much - I'll give that a go.

Iulian Ionescu said:
You must read the Site object of the Form which is of type ISite and get
the Container property from there. The container has a property called
Components which contains all components available on the form (including
tooltips, datasets and so on). You will find that some components that
derive from MarshalByValueComponent will raise an exception when you are
trying to use GetType to see what type of component that is. In this case
you must use the GetService method of the Site object and get a reference to
a IReferenceService object. Using the IReferenceService you can get the
names and types of the components without problems and you can actually even
interact with them... Use the GetComponent, GetName or GetReference methods
of the IReferenceService to do that.
 
I'm struggling to get a reference to an IReferenceService object so an
example would be useful if you would be so kind - thanks.

Iulian Ionescu said:
You must read the Site object of the Form which is of type ISite and get
the Container property from there. The container has a property called
Components which contains all components available on the form (including
tooltips, datasets and so on). You will find that some components that
derive from MarshalByValueComponent will raise an exception when you are
trying to use GetType to see what type of component that is. In this case
you must use the GetService method of the Site object and get a reference to
a IReferenceService object. Using the IReferenceService you can get the
names and types of the components without problems and you can actually even
interact with them... Use the GetComponent, GetName or GetReference methods
of the IReferenceService to do that.
 
None of this works for me since myForm.Site always gives me a null
reference, even though myForm does have components. Help?

Iulian Ionescu said:
You must read the Site object of the Form which is of type ISite and get
the Container property from there. The container has a property called
Components which contains all components available on the form (including
tooltips, datasets and so on). You will find that some components that
derive from MarshalByValueComponent will raise an exception when you are
trying to use GetType to see what type of component that is. In this case
you must use the GetService method of the Site object and get a reference to
a IReferenceService object. Using the IReferenceService you can get the
names and types of the components without problems and you can actually even
interact with them... Use the GetComponent, GetName or GetReference methods
of the IReferenceService to do that.
 
Hi JezB,

Check out my recent post "Enumerating non-ui components from the given
form instance" and its thread. Seems like same struggle that both of us
shared.

Have a good day!

thanks!
-Yasutaka
 
It is indeed ! Have you found a way ? I too only have a form reference (at
least that's all I want to pass to my library routine).
 
Were you able to solve this problem?
Hope you have seen the thread I mentioned. Nice guys in this
forum have solved it for me.

thanks!
-Yasutaka
 
Back
Top