Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

Automatic GUI control generation based on object properties?

This topic is 2521 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a simple class:



public class MyObject
{
public float A;
public bool B;
public int C;
public Vector2 D;
}


I would like to automatically generate GUI objects based on each of the class' properties instead of creating them manually.

I thought about this approach, but I am uncertain how to fully implement it:

- Iterate through each property of the MyObject class (using reflection?), creating a relevant control based on the property type.
- Hook the control data change event up so that each change made will change the original class' property values.

Would there be a better approach to this or have I got the basic idea?

Any help or advice would be welcome.

Share this post


Link to post
Share on other sites
Advertisement

Would there be a better approach to this or have I got the basic idea?

Depends on whether you are using Windows.Forms or not. If you are, then you can simply use a PropertyGrid control to display the properties (note doesn't work for variables, so you have to expose them as properties, which can be a bit of a faff). Otherwise, reflection is your best bet.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!