|
Sorry but i couldn't get idea
Can you provide me whole code?
Pritesh
|
|
|
|
|
In interface we are bound to implement all the functions declared in an Interface but it is not in Abstract Class
Is this comment right if yes plz explain it
Thnx
|
|
|
|
|
Answer was right here[^] on Code Project.
A simple search[^] would have yielded this.
Argh...
But fortunately we have the nanny-state politicians who can step in to protect us poor stupid consumers, most of whom would not know a JVM from a frozen chicken. Bruce Pierson
|
|
|
|
|
Hi,
Given a form
I need to be able to collect the Name Property of all the GUI Objects within it.
- Not Only Nested Controls, But also for example tabPages, ToolStripMenuItems and such.
How can this be done?
Thanks.
(.NET 2.0)
|
|
|
|
|
Each object contains the Controls property, which contain all of the controls that they constrain, so this might be a place to start. Hint - this can be done recursively.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: Each object contains the Controls property
Brilliant minds...
|
|
|
|
|
Colin Angus Mackay wrote: Brilliant minds...
Sometimes our level of genius is quite embarrassing.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
poda....................
|
|
|
|
|
As I said
I need not cycle over the controls only.
For Ex:
Assuming ther is a Control Within the Form of Type - ToolStrip
The ToolStrip Class has no Controls Property
Its Childeren are Beeing held in a collection which can be accessed with the Items Propery
- Now - to get to them I cannot do what u have all mentioned above.
So... my Question Remains - how can this be done?
|
|
|
|
|
Then you will have to use reflection to determine if you need to recurse into a Controls collection or an Items collection.
|
|
|
|
|
I Have just recently heard about reflection
and I'm quite not familiar with the subject.
So... can you please hand me a little piece of code to show how can this be done so I will not have to read all about reflection.
( I'm a litle busy the next days any I need this job to be done as quickly as possible ).
Thanks.
|
|
|
|
|
karoitay wrote: I'm a litle busy the next days any I need this job to be done as quickly as possible
Gee, why didn't you say so. I'll get right on it.
|
|
|
|
|
You can ask every object for its type with .GetType() . You get back a Type object. It has methods on it such as GetMethod , GetProperty and so on. You can get information from the objects those methods return MethodInfo or PropertyInfo and so on. If you find the one you want you can then Invoke it.
Most of this should make enough sense through intellisense. You may have to look up some stuff in the documentation though. It really is worth reading up on so you have a better understanding of the environment in which you are working.
|
|
|
|
|
Thanks, I'll check it out.
|
|
|
|
|
Don't you think, that this would bring a lot of useless matches (ListBox.Items).
I think it would be easier to check out how many control classes don't match "Controls", and do a typecheck ("as") at them!
All the best,
Martin
|
|
|
|
|
Martin# wrote: Don't you think, that this would bring a lot of useless matches (ListBox.Items).
Since I don't know what the overall purpose is I can't say if that would bring lots of useless matches or not. It might do. It might not.
|
|
|
|
|
The Overall purpose is to have a dictionary that will map a Gui object to a bitmask to determine its accessibility to each user of the application
|
|
|
|
|
I wouldn't use reflection. I'd just test if the current control is of a type with a property Controls or whether it is of for example type ToolStrip:
Or the make the code more readable, introduce several overloaded methods that take the different types as a parameter (one overload for control, one for toolstrip, ....)
And call them recursively.
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|
|
Do not forget to check the HasChildren property. Speeds things up.
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|
|
That may depend on how the enumeration is implemented.
|
|
|
|
|
Iterate over the Controls collection.
|
|
|
|
|
by looping through all children of the MainForm and their children and so on.
You can use either recursion or a Stack algorithm.
To get the children use the Controls property of a Control.
To speed things up use property HasChildren to check if a Control has childrens.
-^-^-^-^-^-
no risk no funk ................... please vote ------>
|
|
|
|
|
As I said
I need not cycle over the controls only.
For Ex:
Assuming ther is a Control Within the Form of Type - ToolStrip
The ToolStrip Class has no Controls Property
Its Childeren are Beeing held in a collection which can be accessed with the Items Propery
- Now - to get to them I cannot do what u have all mentioned above.
So... my Question Remains - how can this be done?
|
|
|
|
|
Iterate like people have said, but check the type of the object, and run a separate peice of code to get its items collection, or its child controls etc.
Whatever you do, im pretty sure there isn't some simple function you can use, its gonna take quite the chunk of code, and your probably gonna have to write it all yourself.
|
|
|
|
|
you go to hell.............
|
|
|
|