有3个winfrom窗体,窗体A,窗体B,和窗体C
窗体A和窗体B都都掉用窗体C,但不是同时调用
我怎么在窗体C中判断是窗体A还是窗体B调用的窗体C?

解决方案 »

  1.   

    FormC加个变量,调用时先赋个值?
      

  2.   

    ParentForm属性可以判断父窗体。// The event handler on Form1.
    private void button1_Click(object sender, System.EventArgs e)
    {
        // Create an instance of Form2.
        Form1 f2 = new Form1();
        // Make this form the parent of f2.
        f2.MdiParent = this;
        // Display the form.
        f2.Show();

    C++  复制代码 
       // The event handler on Form1.
    private:
       void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
       {
          // Create an instance of Form2.
          Form1^ f2 = gcnew Form1;      // Make this form the parent of f2.
          f2->MdiParent = this;      // Display the form.
          f2->Show();
       } 
    J#  复制代码 
    // The event handler on Form1.
    private void button1_Click(Object sender, System.EventArgs e)
    {
        // Create an instance of Form2.
        Form1 f2 = new Form1();
        // Make this form the parent of f2.
        f2.set_MdiParent(this);
        // Display the form.
        f2.Show();
    } //button1_Click 
    Visual Basic  复制代码 
    ' The event handler on Form2.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Get the Name property of the parent.
        Dim s As String = ParentForm.Name
        ' Display the name in a message box.
        MessageBox.Show("My parent is " + s + ".")
    End Sub 'button1_Click 
    C#  复制代码 
    // The event handler on Form2.
    private void button1_Click(object sender, System.EventArgs e)
    {
        // Get the Name property of the Parent.
        string s = ParentForm.Name;
        // Display the name in a message box.
        MessageBox.Show("My Parent is " + s + ".");

      

  3.   

    FormC加个
    public int pForm;调用时
    btnFormA_Click
    {
    FromC frm=new FormC();
    frm.pForm=1;
    frm.Show();
    }btnFormB_Click
    {
    FromC frm=new FormC();
    frm.pForm=2;
    frm.Show();
    }
    FormC中判断:
    switch(pForm)
    {
    case 1:
    ...
    break;
    case 2:
    ...
    break;
    default:
    ...
    break;
    }或者FormC的构造函数中直接要求给个调用者的标识也行啊
    类似
    (new FormC("A")).Show();