Good day, dear. On the form are TextBox and Button. Elements created by software. When you click on Button, OpenDialog is called. I am trying to transfer the value of OpenDialog to a TextBox, but I seem to be confused by the visibility of form components. If you specify the Click button in this procedure or the form is not available. Please tell me how to pass the value of the OpenDialog selection result to the TextBox on the form.
public void databaseoptionItem_Click(object sender, EventArgs e) { Form optionForm = new Form(); TextBox databasePathTextBox = new TextBox(); databasePathTextBox.Parent = optionForm; optionForm.Controls.Add(databasePathTextBox); Button databasePathButton = new Button(); databasePathButton.Parent = optionForm; databasePathButton.Click += new EventHandler(databasePathButton_Click); optionForm.Show(); } public void databasePathButton_Click(object sender, EventArgs e) { OpenFileDialog databaseOpenFileDialog = new OpenFileDialog(); if (databaseOpenFileDialog.ShowDialog() == DialogResult.OK) { optionForm. ?(не вижу ни формы ни объектов) } }
optionFormnot a local method variable, but a private field of a form class - Bulson