I create properties in a Form and I do not see them from another Form

3

Inside the file frmPruebas.cs I have created a property:

public partial class frmPruebas : Form
{
    private String mURL;

    public string MURL
    {
        set
        {
            mURL = value;
        }
    }

...
}

And when I try to call it from another Form, it does not have access:

private void frmPrincipal_Load(object sender, EventArgs e)
{
    Form objPruebas = new frmPruebas();

    objPruebas.MURL = txtURL.Text;
    objPruebas.ShowDialog();
}

And it tells me that FORM does not contain a definition for MURL .

Do you know why it can be?

    
asked by Samuel 05.02.2017 в 15:26
source

3 answers

4

The problem is with this sentence:

Form objPruebas = new frmPruebas();

Even if you create an object of type frmPruebas , you assign it to a variable of type Form , which does not have a property MURL .

If you change the sentence to:

var objPruebas = new frmPruebas();

... or:

frmPruebas objPruebas = new frmPruebas();

... will work correctly.

    
answered by 05.02.2017 в 17:19
0

Ideally in your case is to create a public method within the form that allows you to modify the properties you want, so you can modify each instance of that form from outside calling that method in a simple and controlled way.

    
answered by 06.02.2017 в 09:11
0

You need the "set" declaration of the MURL property. Something like that you should have

public partial class frmPruebas : Form
{
    private String mURL;

    public string MURL
    {
        get
        {
            return mURL;
        }
        set
        {
            mURL = value;
        }

    }
    /* Resto del código */

}

    
answered by 07.02.2017 в 20:14