Question: Another beginners question here, coming from Delphi you always have access to another forms controls but in my early days with C# / Visual Studio I am faced with a problem which is proving more difficult than it should be.

I have been getting started by writing a simple notepad style application, I have my main form and a secondary form used to select a line number.

From my main form, I call the goto line number form like so:

```
private void mnuGoTo_Click(object sender, EventArgs e)
{
    Form gotoForm = new GoToForm();
    var dialogResult = gotoForm.ShowDialog();

    if (dialogResult == DialogResult.OK)
    {
        // get the text from gotoForm.editLineNumber.Text
        MessageBox.Show(gotoForm.editLineNumber.Text); // doesn't work
    }
}

```

As you can see from the commented code I have a `TextBox` control called `editLineNumber` which is on my other form (`GoToForm`).

My problem (and likely a beginner question) is why does `editLineNumber` not show in the `intellisense` menu when I type `gotoForm.`?

How do I access the `editLineNumber` control from the form `GoToForm`?

The error message for the `// doesn't work` commented line is:

> 
> Error CS1061 'Form' does not contain a definition for 'editLineNumber'
>  and no extension method 'editLineNumber' accepting a first argument of
>  type 'Form' could be found (are you missing a using directive or an
>  assembly reference?)
> 
> 
> 

Unless I am missing something obvious, why are controls that exist on another form not publically available to all forms? I understand that C# / Visual Studio is different to Delphi but the way Delphi lets you access and see all controls on all forms without any extra works seems more logical to me. Why does C# / Visual Studio hide controls on secondary forms, for what purpose can this be beneficial?

Answer: 
The `editLineNumber` control is private. You can change it to be public, but that's discouraged.

Instead, create a property in `GoToForm` that returns the value you want.

```
public string LineNumber
{
    get { return this.editLineNumber.Text; }
}

```

Now you can just reference your new property:

```
if (dialogResult == DialogResult.OK)
{
    MessageBox.Show(gotoForm.LineNumber);
}

```
Especially if you're new to C# and WinForms, don't touch designer code with a 10 foot pole. As Grant Winney said, use a property:

```
public string GetLineNumberText
{
    get { return this.editLineNumber.Text; }
}

```

It should be mentioned that it's important to be aware of the directional nature of forms. That is to say, if I make `Form1` and then define `Form2` inside of it, you'll want to be careful how you communicate between the two forms. Properties are nearly always a better alternative than accessing form elements directly - it makes the code very difficult to change otherwise. If you, for example, removed `editLineNumber` from the other form or renamed it, *every* instance in the parent form would have to be edited. If you use a property, then you only have to change it in one place.