Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

C#: Is it possible to access a component's property via the component name in a string?

I think, this question is a bit weird.

But I'll try to explain, what I need:

Assume, I have a string with the value "Form" and an integer with the value 1. Is there a way to put these values together (=> 'Form1') and access the properties of Form1 then (similar to getElementById in Javascript)?

For example:

"Form"+1 => Form1

=> Form1.BackgroundColor = Colors.Red;

I hope you got the basic idea of what I'm going to try and I hope you can tell me how I can realise this (if even possible).

Update:

Well, the form was just an example. The object I want to get by name is a SDL.NET sprite. Thanks anyway. I'll try this.

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Using Reflection you can access the properties of an object by name, but not an arbitrary object like this. What you can do is used The OpenForms property of the Application object to retrieve a list of open forms. You can iterate through that looking for the name of the form.

  • clauss
    Lv 4
    4 years ago

    Now you have defined the situation we are able to help. you could desire to verify if the shutter is easy sensitized for vehicle exposure. despite if this is mechanical, the postpone of the image resistor, could be so great as to spark off the sunshine booster after the shutter has closed. this is greater efficient if feasible, to faucet into the availability to the interior flash, and repeat this ability via a transistor on the distant flash.

  • Anonymous
    1 decade ago

    MSDN is better place to ask question like this.

    After opening below link see left panel.

    BEST REGARD

Still have questions? Get your answers by asking now.