2013-04-26 4 views
-5

두 번째 양식의 첫 번째 양식에서 메서드를 호출해야하는데 두 가지 형식이 필요합니다. 위의 오류로 인해 막혔습니다. 두 번째 양식이 닫히면 양식을 닫아야합니다. 그것은 여기 일어나고이름 'fe'가 현재 컨텍스트에 존재하지 않습니다.

namespace WindowsFormsApplication1 
{ 
public partial class Flightentry : Form 
{ 

    flightDetail fd = new flightDetail(); 

    private Passengerdetail pd; 


    public Flightentry(Passengerdetail paDet) 
    { 
     InitializeComponent(); 

     pd = paDet; 
    } 

    private void label5_Click(object sender, EventArgs e) 
    { 

    } 


    private void button2_Click(object sender, EventArgs e) 
    { 
     pd.insertData();\\i call the insert method from the previous form here. 

     fd.Insert(comboBox1.Text,comboBox2.Text,comboBox3.Text,textBox3.Text,textBox8.Text,dateTimePicker1.Text,textBox6.Text,textBox5.Text); 
    } 

    private void Flightentry_Load(object sender, EventArgs e) 
    { 

    } 

    private void Flightentry_FormClosing(object sender, FormClosingEventArgs e) 
    { 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     this.Owner.Show(); 
     this.Hide(); 
    } 
} 

}

+6

뭔가를 원한다고 생각 변수에 대한 선언을 작성하면 컴파일 오류가 발생합니다. 무슨 일이 일어날 것이라고 생각 했니? – siride

+0

아니, 아니, 네가 들여다 볼 수 있도록 해달라고 했어. – MoniXx

+0

나를 믿어. 우리가 필요한 선언을 없애면 어떻게되는지 알지. – siride

답변

4

namespace WindowsFormsApplication1 
{ 
public partial class Passengerdetail : Form 
{ 
    passengerDetailClass pd = new passengerDetailClass(); 

    Flightentry fe = new Flightentry();  //if i remove this code 

    public Passengerdetail() 
    { 
     InitializeComponent(); 
     fe.FormClosed += new FormClosedEventHandler(fe_FormClosed); //this line gives error mentioned above. 
    } 

    void fe_FormClosed(object sender, FormClosedEventArgs e) 
    { 
     this.Close(); 
    } 

    private void label1_Click(object sender, EventArgs e) 
    { 

    } 

    private void Passengerdetail_Load(object sender, EventArgs e) 
    { 

    } 

    private void button2_Click(object sender, EventArgs e) 
    { 

     Flightentry fe = new Flightentry(this);  //this code lets me access the method from the other form removing it will mean no method =(

     this.Hide(); 
     fe.Owner = this; 
     fe.ShowDialog(); 
     this.Show(); 
    } 

    public void insertData() 
    { 
     pd.Insert();  //i want to access this method 
    } 

} 

}

다음과 같다 번째 형태의 코드 ...? 당신이 당신의 의견에 비추어 fe


에 대한 선언을 주석 처리했기 때문에

//Flightentry fe = new Flightentry();  //if i remove this code 

public Passengerdetail() 
{ 
    InitializeComponent(); 
    fe.FormClosed += new FormClosedEventHandler(fe_FormClosed); //this line gives error mentioned above. 
} 

, 나는 당신이 주석 있음을 놀라게하는 이유는 다음

Flightentry fe; 

public Passengerdetail() 
{ 
    InitializeComponent(); 
    fe = new Flightentry(this) 
    fe.FormClosed += new FormClosedEventHandler(fe_FormClosed); //this line gives error mentioned above. 
} 

... 

private void button2_Click(object sender, EventArgs e) 
{ 
    this.Hide(); 
    fe.Owner = this; 
    fe.ShowDialog(); 
    this.Show(); 
} 
+0

예 ... 여기에서 일어나는 일입니다 .... – MoniXx

+0

하지만이 줄을 제거하면 Flightentry fe = new Flightentry (this); 난 다른 양식 – MoniXx

+0

@ 메서드를 액세스 할 수 없을거야 당신이 그 라인을 PassengerDetail에 대한 생성자에 넣을 수 있습니다. – siride

관련 문제