I'm showing a modal form with 2 textboxes; first textbox is passed from the caller by passing a string to the constructor of the modal form. The 2nd textbox is blank and I type data into it and then click OK.
I cannot retrieve the value typed into the 2nd textbox (in fact, a breakpoint in my btnOK_click code does not stop execution).
MetaDataForm getMetaData = new MetaDataForm(theRootFolder.FolderPath);
getMetaData.ShowDialog();
if (getMetaData.DialogResult == DialogResult.OK)
    {
        string d1 = getMetaData.Meta1;
        string d2 = getMetaData.Meta2;     // this is always null !
and in the modal form:
public partial class MetaDataForm : Form
{
    public string Meta1 { get; set; }     // via auto-implemented properties
    public string Meta2 { get; set; }
    public MetaDataForm(string folder)
    {
        InitializeComponent();
        this.label1.Text = folder;
        this.Meta1 = ParseOutlookFolder(folder);
        this.txtMeta1.Text = this.Meta1;
    }
    private string ParseOutlookFolder(string folder)
    {
        string[] a = folder.Split('\\');
        return a[a.Length - 1];
    }
    private void btnOK_click(object sender, EventArgs e)
    {
        this.Meta2 = this.txtMeta2.Text;  // copy from text box into public property (not working?)
        this.Meta1 = this.txtMeta1.Text;
        this.DialogResult = DialogResult.OK;   // added per 1st reply below but no improvement
        this.Close();
    }
EDIT: Please note:
When a breakpoint is set on this line in the btnOK_click event:
this.Meta2 = this.txtMeta2.Text;    // copy from text box into public property
..it is never "hit". Could this be why when I do stop execution on this line:
string d2 = getMetaData.Meta2;   开发者_JAVA技巧  // this is always null !
..it is always null ?
In short, how do you grab a value from a form when you resume in the main code after showing a modal form?
(in fact, a breakpoint in my btnOK_click code does not stop execution
Sounds like the event handler got removed while doing changes on the form, check the designer code for something like:
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
or check the Click event handler is pointing to the correct function in the design view for this form.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论