Laman

Senin, 04 Oktober 2010

menutup form satu dari form dua di C# (C Sharp)


Posting tutorial kali akan dibahas tentang bagaimana cara menutup form satu dari form dua, dalam beberapa kasus kita pasti akan menjumpai suatu keadaan dimana kita harus menutup form dua akan tetapi fokus berada pada form satu. jika bingung, silahkan download contohnya disini. pada file binary yang telah di download tadi, coba anda jalankan, setelah itu tampilkan form 2 (dengan melakukan klik button1 yang ada pada form 1) seperti gambar di bawah ini.
setelah iti tutup form2 (dengan cara klik icon x yang berada di kanan atas) maka form satu juga akan di close, berikut ini adalah source codenya
tuliskan code pada form 1
private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2(this);
            frm2.ShowDialog();
        }

tulis code ini pada form2
private Form1 form1;
        public Form2( Form1 frm1)
        {
            this.form1 = frm1;
            InitializeComponent();
        }       

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            form1.Close();
        }

 Gambar 1. Preview aplikasi yang dijalankan

jika anda masih bingung, ini adalah urutan pembuatan projectnya
1. pertama yang harus kita lakukan adalah membuat project dengan dua form, misal form pertama kita beri nama form 1 dan form kedua kita beri nama form2. 
2. selanjutnya adalah tambahkan button pada form pertama dan tambahkan code berikut ini
Form2 frm2 = new Form2(this);
            frm2.ShowDialog();

3. rubahlah code construktor pada form2 agar menjadi seperti dibawah ini

private Form1 form1;
        public Form2( Form1 frm1)
        {
            this.form1 = frm1;
            InitializeComponent();
        }     

4. dan langkah terakhir adalah menambahkan event closing untuk melakukan closing pada form 1, codenya seperti dibawah in
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            form1.Close();
        }                                                        

Berikut ini adalah source lengkap untuk form 1
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {      
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2(this);
            frm2.ShowDialog();
        }
    }
}

dan ini adalah source lengkap untuk form 2
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        private Form1 form1;
        public Form2( Form1 frm1)
        {
            this.form1 = frm1;
            InitializeComponent();
        }       

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            form1.Close();
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }        
    }
}

JIka sampai disini masih belum mengertu/bingung silahkan tinggalkan email anda di kotak komentar, akan saya send full projectnya ke email anda, atau contact us on informasi@csharp-indonesia.com

NB : Dalam tutorial ini program ditulisa menggunakan IDE Visual studio 2010. dengan target framework 2.0 . Sehingga minimal komputer harus terinstal windows xp untuk bisa menjalankan program *.exe nya, Sedangkan untuk membuka projectnya mau tidak mau harus menginstal microsoft visual studio 2010

23 komentar:

  1. Bold, classic and stunningly captivating, a pair of Ray-Ban Aviator sunglasses is a charmer. They add a dash of chic to the wearer’s look. Whether it’s a casual outing or a formal ray ban outlet event, donning a pair of these sassy sunnies can instantly draw attention towards you. Meant to perfectly complement both casual as well as sophisticated tailored outfits; they are the perfect match to accentuate your class, glamour and exuberant taste.Though the classic black Ray-Ban Aviator sunglasses have always been a favorite amongst all the fashion followers, the current fad is to pep up your style quotient with a pair of Ray-Ban Aviator sunglasses with flash lenses. Super stylish, flamboyant and absolutely glamorous, they are a hot favourite among celebrities and fashion icons ray ban wayfarer sale alike.
    On the other hand, Wayfarers might not suit every face shape. These shades are more suitable for a person with a long or rectangular face. Today, one can also choose from Wayfarers in various colours too.The main purpose of sunglasses is to protect your eyes from the sun. And the protection comes entirely from the lenses that are used. One ray ban sunglasses must know that there are different types of lenses available with Ray-Bans and one must select them according to the need.Standard lenses: Initially made for military use, the iconic G-15 and B-15 lenses offer optimal levels of clarity, comfort and protection.Gradient: Keeping up with the latest trends, gradient lenses come in a wide range of exciting colors. So, if vintage colours cheap ray bans offer limited choice, one can go for colourful gradient lenses.
    Obviously, for Ray-Ban models with very thin temple "arms", like Aviators, no logo is present.Look for the model number inside the “arms” of the glasses. Look at the inside of the "arms" of the glasses that rest on your ears. If you have Wayfarers or Clubmasters, you should see white text ray bans cheap inside the arms. On the left arm, you'll see your glasses' serial and manufacturing numbers. On the right arm, you should see the Ray-Ban logo, "Made in Italy", and a stylized "CE" (which signifies that the glasses are certified to be sold in Europe). If this text is missing, smudged, or poorly-printed, your glasses are almost certainly fakes.
    The Ray-Ban logo ray ban glasses will be etched on both the lenses. On the right lens will be the Ray-Bay logo, while on the left lens, right below the hinges will be the initials ‘RB’.If the sunglasses have nose pads, there will be the initials ‘RB’ engraved right at the centre of the metal piece.And there are a few other points which you should keep in ray ban clubmaster mind, as far as original Ray-Ban sunglasses are concerned.Pre-2000 models of Ray-Ban sunglasses will have the initials ‘BL’ instead of ‘RB’ on the left lens.

    BalasHapus
  2. God loves righteous and faithful , i wish you become one of them , best wishes to be guided to the right way to god
    nasihnetwork
    sai
    nasihnetwork
    sai

    BalasHapus
  3. thank you for the information provided, we are waiting for the next info at cara mengugurkan kandungan

    BalasHapus
  4. you can try these out replica louis vuitton go to my site replica gucci her explanation bag replica high quality

    BalasHapus