code for how to call an event of a form into another form in c# window forms

csharp Madrid, Spain
  • 12 years ago

     

  • 12 years ago

    isn't that a bit much? he can just subscribe to the events from with the other form

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Windows.Forms;

    namespace Demo

    {

    class Program

    {

    static void Main(string[] args)

    {

    Form form1, form2;

    form1 = new Form();

    form2 = new Form();

    form1.Text = "Main form, close this to exit";

    form2.Text = "Second form, closing this does nothing";

    form2.Load += new EventHandler(form2_Load);

    form1.FormClosing += new FormClosingEventHandler(form1_FormClosing);

    form2.Show();

    Application.Run(form1);

    }

    static void form1_FormClosing(object sender, FormClosingEventArgs e)

    {

    MessageBox.Show("Closing Application");

    }

    static void form2_Load(object sender, EventArgs e)

    {

    MessageBox.Show("Form 2 loaded");

    }

    }

    }

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only two kinds of languages: the ones people complain about and the ones nobody uses” - Bjarne Stroustrup