Matimont
Matimont

Reputation: 759

modify object on a form other than the one where was created

I have an object that I create in Form1 and then I pass that object to Form2.

Is this a good approach to modify the properties of the Form1 object instance (pois_por_punto)?

So far this is what I did:

in Form1:

public List<POI> pois_por_punto;
pois_por_punto = new List<POI>();

Then:

   private void btn_editar_pois_Click(object sender, EventArgs e)
        {
            Form formulario = new Form2(this, pois_por_punto);
            formulario.ShowDialog();
        }

In Form2:

public partial class Form2: Form
    {
        private List<POI> _pois;

   public Editar_POIs(Form1 formprincipal, List<POI> pois)
        {
            _pois = pois;
        }

Then in my code I change the _pois properties and then I do this:

 formprincipal.pois_por_punto = _pois;

}

My POI Class is like this

  public class POI
    {
        public decimal POI_x { get; set; }
        public decimal POI_y { get; set; }
        public decimal POI_z { get; set; }
    }

Upvotes: 0

Views: 26

Answers (1)

Markus
Markus

Reputation: 761

The answer is somewhat a matter of circumstance. There are patterns that are appropriate for what you might call industrial grade code, and there are patterns that are appropriate for getting stuff done and going to the park. With that said, I'm going to say that it's probably fine the way it is, if it works; however, here are some resources that you may find helpful:

This answer may also be useful because it describes separation patterns that you can use for projects like this one.

Upvotes: 1

Related Questions