Sign in to follow this  

Grabbing textbox values from another form

Recommended Posts

Hello all, I am in the process of creating a tile based game editor using XNA and C#. One of my menu items is of course creating a new layer on the current map. This is the code that loads a new form when the user clicks on new layer:
frmNewLayer newLayer = new frmNewLayer();

tileLayer = new TileLayer(newLayer.txtLayerName.Text);
tileLayerWidth = int.Parse(newLayer.txtLayerWidth.Text);
tileLayerHeight = int.Parse(newLayer.txtLayerHeight.Text);

Simple question I suppose. I am grabbing the text values for the tileLayer, tileLayerWidth, and tileLayerHeight after the newLayer form OK button was clicked (I am checking the values of the textboxes in the forms OK button click, so the values should be valid once it returns here). So far, this method is working just fine, but I got to wondering, am I just getting lucky at this point in capturing the .Text values from the newLayer form, since the this.Close() method is called in the frmNewLayer after validating the textbox values? Thanks, Shawn *Edit* - Just to clarify, I am wondering if I am still able to retrieve those values because the GC has not ran on the form (the frmNewLayer) even though it has been closed? If that is the case, what would be a better way to do this?

Share this post

Link to post
Share on other sites
I don't think you're getting lucky, I think it's fine. If you're ensuring that the data has been passed (i.e. copied) before you destroy the original form then providing you don't try to refer back to the previously destroyed object then I can't immediately see any problems.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this