| |

VerySource

 Forgot password?
 Register
Search
View: 1040|Reply: 7

Ask a simple question about WindowForm

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-2 16:00:01
| Show all posts |Read mode
Existing AForm, BForm, CForm three forms, A, B can call up C form
If used:
CForm frm = new CForm ();
frm.Owner = this;
frm.ShowDialog ();

In the C form, you can set the variables in A and B.
If used: AForm frm = (AForm) this.Owner;
      frm.x = 100;
Or: BForm frm = (BForm) this.Owner;
      frm.x = 100;

When the program is running, how does the CForm form know whether it is called AForm or BForm and return a value?
Reply

Use magic Report

0

Threads

21

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 United States

Post time: 2020-1-2 19:18:01
| Show all posts
declare a property of type Form in CForm and assign a form to the property before calling CForm.ShowDialog
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-2 20:27:02
| Show all posts
The easiest way ﹕
if (Type.GetType ("Test.AForm") == this.Owner.GetType ())
{
    ((AForm) this.Owner) .x = 100;
}
else
{
    ((BForm) this.Owner) .x = 100;
}

Note: Change the Test in "Test.AForm" to the namespace of your AForm class. It must not be omitted.
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-1-3 10:03:01
| Show all posts
Agree upstairs ..

reflection:

using System.Reflection;

            if (Type.GetType ("TestForm.AForm"). Equals (this.Owner.GetType ()))
            {
                // Indicate that the parent form of this C form is A
                //operating
            }
            else
            {
                 // otherwise B
                 //operating
            }
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-3 10:12:01
| Show all posts
top
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-3 10:27:01
| Show all posts
Top one!
Reply

Use magic Report

0

Threads

17

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-1-3 15:27:01
| Show all posts
You can set a global variable. When A calls C, it assigns the variable A. When B calls C, it assigns the variable B.

Such as class FromA ()
{
    public string strparent = ""

    private void call C ()
    {
         strparent = "A";
         // u can call form c here;
     }
}

class FromB ()
{

    private void call C ()
    {
         FormA.strparent = "B";
         // u can call form c here;
     }
}

You know who called it by reading the value of FormA.strparent.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-3 21:15:01
| Show all posts
using System.Reflection;

                        if (Type.GetType( "TestForm.AForm ").Equals (this.Owner.GetType()))
                        {
                                //Description that the parent form of the C form is A
                                //Operation
                        }
                        else
                        {
                                  //Otherwise it is B
                                  //Operation
                        }
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list