Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
List all the .Text properties of all controls of an asse
Message
From
03/08/2004 12:44:27
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00930366
Message ID:
00930415
Views:
11
Hi, Eric,

I've done some things with reflection, but I've never specifically tried what you've asked.

Right now I'm not able to give you a full response, but maybe I can give you something to get you started or trigger some ideas. Maybe someone else can jump in who has worked more with it.

Basically, I think you need to load the assembly, go through the types/objects in it, and see how many are of a type that might contain controls with a text property...for instance.
Assembly aAssembly = Assembly.LoadFrom("MyAssembly.DLL");
foreach(Type tType in aAssembly.GetTypes()) 
   if(  "tType is a Windows System Form")                //pseudocode, not positive how you would code it
      object oObject = Activator.CreateInstance(tType);
      System.Windows.Forms.Form oForm = (System.Windows.Forms.Form)oObject;
      foreach(Control cc in oForm.Controls)
         if(cc is TextBox)                     // or check if the control contains a text property
            MessageBox.Show(cc.Text);
    }
Now, I'm not 100% certain how to check if the type is something that might have controls in it (form, usercontrol), etc. Also, when I'm looping through the controls, I'm only checking to see if it's a textbox.

I was curious about checking ahead of time to see if a control 'has' a particular property, and I asked Bonnie Berent...she suggested that type.GetProperty() might help. She mentioned that Rick Strahl discussed this at http://west-wind.com/weblog/posts/256.aspx ... there's something there about using .GetProperty(). {Thanks, Bonnie!}

So this is maybe half an answer at best - I may look into this later, for my own curiosity of better understanding reflection, but hopefully some of this *might* help.

Kevin
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform