2

投稿が重複していますが、質問には回答がありません。私の質問は、新しいフォームがメインフォーム内に作成されているかどうかです

var editor = new Edit(itemList, itemListBox);
editor.Show();

編集するデータのタイプは次のとおりです。

Dictionary<int, Item>

アイテムは以下:

public class Item
{
    public string @Url { get; set; }
    public string Name { get; set; }
    public double Price { get; set; }

    public Item(string @url, string name, double price)
    {
        this.Url = url;
        this.Name = name;
        this.Price = price;
    }

    public override string ToString()
    {
        return this.Name;
    }
}

メイン ウィンドウ フォームで ListBox を更新できるように、エディターを閉じたときにハンドラーを追加するにはどうすればよいですか。

4

2 に答える 2

2

Form.Closedイベントのイベントハンドラーを追加するか

var editor = new Edit(itemList, itemListBox);
editor.Closed += OnEditorClosed(); // your eventhandler here
editor.Show();

ShowDialogまたは、代わりに使用してモーダルダイアログを作成するだけですShow

var editor = new Edit(itemList, itemListBox);
editor.ShowDialog(); // execution will stop here until editor is closed
于 2013-09-09T07:01:46.970 に答える
0

Form には、FormClosing と FormClosed のイベント ハンドラがあります。2番目ではフォームのデータがすでに破棄されている可能性があるため、最初のものを使用する方が良いと思います。そう:

editor.FormClosing += new FormClosingEventHandler(editor_FormClosing);

private void editor_FormClosing(object sender, FormClosingEventArgs e)
{
    Edit editor = (Edit)sender;
    // update data on main form here
}
于 2013-09-09T07:06:02.273 に答える