.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

ถามเกี่ยวเปิดปิด windows form ครับ Options · View
supbo
Posted: Monday, June 30, 2008 12:05:19 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 6/30/2008
Posts: 1

มี winform 3 form

form1,form2 และ form3
 
1.เมื่อ กดปุ่ม ที่ form1 ให้โชว์ form2
 
Form1 

private void button1_Click(object sender, EventArgs e)Form2 f = new Form2();

{

 

f.ShowDialog();

}
 
2.กดปุ่มที่ form2 สั่งให้ปิด form2 ,ปิด form1 และเปิด form3
Form2
 

private void button1_Click(object sender, EventArgs e)this.Close(); หรือ this.Hide();Form1. f1 = new Form1();Form3 f3 = new Form3();

{

 

 

f1.Close(); หรือ this.Hide();

 

f3.Show();

}
 
คำถามครับ form2 ปิด ทำไม form1 ไม่ปิดหรือซ่อนหายไป แต่กลับโชว์ active อยู่หน้า form3 อีกต่างหาก
จะเขียน Code อย่างไง รบกวนด้วยนะครับ
mocking1
Posted: Thursday, July 03, 2008 4:14:24 PM
Rank: มือสมัครเล่น
Groups: Member

Joined: 6/26/2008
Posts: 16
Location: thailand

เท่าที่เคยผ่านตามานะครับ ผมว่า Form1 ไม่สามารถใช้คำสั่ง from1.close ได้ เพราะมันเป็น Main Form ถ้าใช้Hide น่าจะได้

natdanai4
Posted: Friday, July 11, 2008 2:06:35 PM

Rank: มือสมัครเล่น
Groups: Member

Joined: 7/7/2008
Posts: 10
Location: bangkok
ได้สิค่ะ
kosinrecon
Posted: Sunday, October 05, 2008 1:39:34 PM
Rank: มือสมัครเล่น
Groups: Member

Joined: 10/1/2008
Posts: 14
Location: surin

natdanai4 wrote:
ได้สิค่ะ

ก็ได้คับ แต่ ถ้า close แล้วโปรแกรมก็จะปิดไปด้วย

mrxc
Posted: Sunday, October 05, 2008 3:58:04 PM
Rank: มือเทพ
Groups: Member

Joined: 3/6/2008
Posts: 177
Location: TH

ลองแบบนี้ดูครับ รักษา form 1 ไว้ไม่ให้ปิดตัวเอง เมื่อปิดก็ซ่อนพอ



// Form 1

    public partial class Form1 : Form
    {
        public Form3 f3;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.FormClosed += new FormClosedEventHandler(f2_FormClosed);
            f2.Show();
        }

        private void f2_FormClosed(object sender, FormClosedEventArgs e)
        {
            f3 = new Form3();
            f3.FormClosed += new FormClosedEventHandler(f3_FormClosed);
            f3.Show();
            this.Hide();
        }

        private void f3_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Show();
        }
    }

// Form 2

    public partial class Form2 : Form
    {
         public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }


Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by