Click here to Skip to main content
15,906,574 members
Home / Discussions / C#
   

C#

 
GeneralRe: parent child communication Pin
PIEBALDconsult21-Jan-09 7:13
mvePIEBALDconsult21-Jan-09 7:13 
AnswerRe: parent child communication Pin
DaveyM6921-Jan-09 7:21
professionalDaveyM6921-Jan-09 7:21 
GeneralRe: parent child communication Pin
bfis10813722-Jan-09 3:32
bfis10813722-Jan-09 3:32 
GeneralRe: parent child communication Pin
DaveyM6922-Jan-09 4:53
professionalDaveyM6922-Jan-09 4:53 
GeneralRe: parent child communication Pin
bfis10813722-Jan-09 4:56
bfis10813722-Jan-09 4:56 
GeneralRe: parent child communication Pin
DaveyM6922-Jan-09 5:09
professionalDaveyM6922-Jan-09 5:09 
GeneralRe: parent child communication Pin
bfis10813722-Jan-09 12:55
bfis10813722-Jan-09 12:55 
GeneralRe: parent child communication Pin
DaveyM6923-Jan-09 1:07
professionalDaveyM6923-Jan-09 1:07 
If you actually want the book list to be generated when the form closes then there are a couple of ways.

The simplest is to override the OnFormClosing (example 3 in last post). In the commented section after the base event is raised, check Cancel and if false, raise acustom event.

It is possible to customize the FormClosing. FormClosingEventArgs derive from CancelEventArgs, so we can do something similar. The code below works. It's a little more complicated than the first option but this way only the one event is fired.
public partial class Form1 : Form
{
    public new event EventHandler<CreateOrderEventArgs> FormClosing;
    private List<BookOrder> orderedBooks;
    public Form1()
    {
        InitializeComponent();
    }
    List<BookOrder> GenerateBookList()
    {
        List<BookOrder> result = new List<BookOrder>();
        // do your stuff
        return result;
    }
    protected override void OnFormClosing(FormClosingEventArgs e)
    {
        EventHandler<CreateOrderEventArgs> eh = FormClosing;
        if (eh != null)
        {
            orderedBooks = GenerateBookList();
            CreateOrderEventArgs createOrderEventArgs = new CreateOrderEventArgs(
                e, orderedBooks);
            eh(this, createOrderEventArgs);
        }
    }
}
public class CreateOrderEventArgs : CancelEventArgs
{
    private CloseReason m_CloseReason;
    private List<BookOrder> m_OrderedBooks;
    public CreateOrderEventArgs(
        FormClosingEventArgs e, List<BookOrder> orderedBooks)
    {
        m_CloseReason = e.CloseReason;
        Cancel = e.Cancel;
        m_OrderedBooks = orderedBooks;
    }
    public CloseReason CloseReason
    {
        get { return m_CloseReason; }
    }
    public List<BookOrder> OrderedBooks
    {
        get { return m_OrderedBooks; }
    }
}
public class BookOrder
{
    // your stuff here
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

AnswerRe: parent child communication Pin
Giorgi Dalakishvili21-Jan-09 8:48
mentorGiorgi Dalakishvili21-Jan-09 8:48 
QuestiontoolStrip Quickie Pin
musefan21-Jan-09 6:09
musefan21-Jan-09 6:09 
AnswerRe: toolStrip Quickie Pin
#realJSOP21-Jan-09 8:00
professional#realJSOP21-Jan-09 8:00 
AnswerRe: toolStrip Quickie Pin
musefan21-Jan-09 8:29
musefan21-Jan-09 8:29 
Questionhow to get file present on another web site Pin
sushilbondre21-Jan-09 6:05
sushilbondre21-Jan-09 6:05 
AnswerRe: how to get file present on another web site Pin
musefan21-Jan-09 6:13
musefan21-Jan-09 6:13 
AnswerRe: how to get file present on another web site Pin
Dave Kreskowiak21-Jan-09 7:02
mveDave Kreskowiak21-Jan-09 7:02 
GeneralRe: how to get file present on another web site Pin
sushilbondre23-Jan-09 4:41
sushilbondre23-Jan-09 4:41 
GeneralRe: how to get file present on another web site Pin
Dave Kreskowiak23-Jan-09 13:49
mveDave Kreskowiak23-Jan-09 13:49 
GeneralRe: how to get file present on another web site Pin
sushilbondre24-Jan-09 4:17
sushilbondre24-Jan-09 4:17 
GeneralRe: how to get file present on another web site Pin
Dave Kreskowiak24-Jan-09 4:42
mveDave Kreskowiak24-Jan-09 4:42 
GeneralRe: how to get file present on another web site Pin
sushilbondre25-Jan-09 18:46
sushilbondre25-Jan-09 18:46 
GeneralRe: how to get file present on another web site Pin
Dave Kreskowiak26-Jan-09 2:06
mveDave Kreskowiak26-Jan-09 2:06 
Questionretrieving, editing, updating a single table row Pin
Lodeclaw21-Jan-09 5:31
Lodeclaw21-Jan-09 5:31 
QuestionFile creation and naming increment Pin
Terick21-Jan-09 4:55
Terick21-Jan-09 4:55 
AnswerRe: File creation and naming increment Pin
EliottA21-Jan-09 5:02
EliottA21-Jan-09 5:02 
GeneralRe: File creation and naming increment Pin
musefan21-Jan-09 5:10
musefan21-Jan-09 5:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.