C# and forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • golden-i
    New Member
    • May 2006
    • 1

    C# and forms

    I will try to be as clear as i can

    Iam new in C# and iam making a very simple C# application in VS ( Smart device application ) , in this application The main form ( Form1 ) Creats a new form (form2) which has a button to close it , so i want to make the ( Form1 ) take some action when the (form2) is closed for example it will show a message or something.

    :) how can i do that ?

    can i add an event in the form1 which will do the action , HOW ?


    Thanks in advance :)
  • Atran
    Contributor
    • May 2007
    • 319

    #2
    This Message for i-golden.
    Important License before Begin: make all forms, projects..... NAMES Default.
    First Open Visual C#, Seconde Create a new Project (Windows Forms) Called the Name you Like. Then you see your Form (name: Form1).
    Now add A Seconde Form (name: Form2).
    Now Stay in The Form1. Clicking Right Mouse button on the Form1 then Click > View Code. and you See the Form1 Code.
    Now you can add codes for the Code, write:

    using System;
    using System.Collecti ons.Generic;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows. Forms;

    namespace WindowsApplicat ion1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeCompo nent();
    Form2 x = new Form2(); //Important: ADD THIS SCRIPT
    x.Show(); //Important: ADD THIS SCRIPT
    }
    }
    }

    After that Open the Form2, and Clicking Right Mouse Button on it, then Click > View Code. and you see the code of Form2, write this code:

    using System;
    using System.Collecti ons.Generic;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows. Forms;

    namespace WindowsApplicat ion1
    {
    public partial class Form2 : Form
    {
    public Form2()
    {
    InitializeCompo nent();
    this.FormClosed += new FormClosedEvent Handler(Form2_F ormClosed);
    }

    void Form2_FormClose d(object sender, FormClosedEvent Args e)
    {
    MessageBox.Show ("You Closed The Window");
    }
    }
    }

    If you do not understand send me email at Atran_atran@yah oo.com to send you the example.

    For more help ATRAN_ATRAN@YAH OO.COM
    BYE

    Comment

    Working...