In the form programming of C, I want to define variables in one phase window and call them in anothe

Updated on technology 2024-03-03
20 answers
  1. Anonymous users2024-02-06

    That's it, this belongs to the parameter transfer between forms, there are many ways!

    One of them. a window.

    in a: window public string publicstring;

    b window. Call a

    a a=new a();

    Custom becomes two";;

  2. Anonymous users2024-02-05

    1) In the background generation of form3.

    Code 2) In form1, suppose you click button1 to display form3, backend**.

  3. Anonymous users2024-02-04

    When do you want the textbox in form3 to show the value of the textbox in form1?

  4. Anonymous users2024-02-03

    Set a variable as a global variable in form A assumes public static string a;

    Assign a value to the value change event of the control: a=name of the control. text;

    Because a is a static global variable, it can be accessed directly when the b form uses the value of a; As for whether it is an assignment or a substitution operation, it can be obtained.

  5. Anonymous users2024-02-02

    It's easy.

    **As follows: Suppose the definition of the variable in form1 is: public string form1str="form1";

    In form2: form1 myform1 = new form1();

    string form2str = ;

    This will allow you to get a reference to the variable in form1!

    However, it is not recommended to use it this way, you can use attributes to do it.

    **As follows: in form1: private string form1str;

    public string form1strset

    ** similar in form2: form1 myform1 = new form1();

    string form2str = ;

    This is in line with the principle of object-oriented encapsulation!

  6. Anonymous users2024-02-01

    When two windows are related:

    from2 f = new from2();

    f.variable = variable of f1;

    Then you can use it in form2.

    Either public static

  7. Anonymous users2024-01-31

    Define this variable as public static string;

    Then use form1 in form2this variable.

  8. Anonymous users2024-01-30

    OK. The simple method, as the ls2 bit says, is to declare static variables in the first form and then use them directly in the second form.

    However, this static is okay if it is less, and it is best to use the commission if there are many things to be saved.

  9. Anonymous users2024-01-29

    Yes! Define the variable with the public static modifier: public static string txt="";

    txt=;

  10. Anonymous users2024-01-28

    For example, if form A wants to call the value of a textbox in form B, define a public static variable in form B, the type is string, and the variable name is str, which is used to store the value in the textbox, so that in form A, it can be directly used to call the value of its textbox.

  11. Anonymous users2024-01-27

    Can be in addition to the ground floor method; You can also define a property get, set

  12. Anonymous users2024-01-26

    Set the modifiers property of control 1 in form 1 to public, and form 2 can access this control, which is private by default.

  13. Anonymous users2024-01-25

    Yes, you can create a new class file in your project, and then define a static variable in that file, for example, in the class file (.).CS file), I'll take int as an example, public static int i="";Note that you must add public.

    Then you can call the assignment in form2, you can assign the value of the global variable after changing the value to i (, and then call i in form1.

  14. Anonymous users2024-01-24

    The other window must first have a variable that points to the window, and then the variables of the window are used to access the variables under the instance of this window.

    Oh, and by the way, the access to the target window variable should be public.

  15. Anonymous users2024-01-23

    If you need to call it, just add a public method to the form1 window and call it in form2. For example:

    public void plusnumber(int number)form2 can be used directly:;

  16. Anonymous users2024-01-22

    You just need to write a public method in form2 to commit the data, and then call it in form1?

  17. Anonymous users2024-01-21

    If you call another window's control directly, it can cause thread-safety issues, which is best achieved using a delegate.

  18. Anonymous users2024-01-20

    1. Define it as a global static variable that can be called directly in other forms, and there is no need to pass the form:

    Definition: public static datatable mytable=new datatable("datacurrent");

    Call: 2, put it directly into the constructor of the form and pass it to the new form, such as the form2:

    Constructor for the new form: public form2(datatable dt).

    Get an instance of the new form: form2 form=new form2(mytable);

    I hope it helps, and if you have any questions, please ask or hi

  19. Anonymous users2024-01-19

    Since this variable is local, you need to set it to global in order to call it, outside of the method.

    If you want to call the variables in form1 in form2, then you need to pass form1 as an argument when you open form2, and then you can call the global variables in form1

  20. Anonymous users2024-01-18

    In the click event in form1, write the following **::

    private void button1_click(object sender, eventargs e)

    in form2.

    form1 owner = (form1);

    To get mytable through the owner, and importantly, change the access modifier of mytable to protected or public!

Related questions
9 answers2024-03-03

The original meaning of the question is to implement the function of one queue with two stacks. >>>More

16 answers2024-03-03

Yes. I have a way. You look for a pig. Then write the name of the person you like on the pig. And then go to get married with pigs. >>>More

9 answers2024-03-03

The United States is the most generous country in the world in awarding scholarships, but even so, the proportion of mainland applicants, especially mainland undergraduate applicants, who can get full scholarships for doctoral degrees in the United States is very small every year. Study Abroad 360 Lanzhou Wei Binghua pointed out that usually, applicants who can win the full doctoral award are often outstanding in all aspects, especially the research background is very important. Applicants who are determined to strive for the full doctoral award of a prestigious university in the United States should start planning at least from the sophomore year, and make corresponding preparations from various aspects such as average grades, research background, and even contact recommenders.

14 answers2024-03-03

It means that you haven't let go of it at that time and started a new relationship.

13 answers2024-03-03

Honestly, I don't even want to comfort you. As a girl, it's like this because of your birthday, it's good for you to be angry and play a tantrum, why do you always talk about breaking up. Who will stand this? >>>More