C How to get a string in Form1 in Form2

Updated on technology 2024-02-09
24 answers
  1. Anonymous users2024-02-05

    The easiest way to do this is to create a constructor with a string parameter in form2, and then generate a form2 form.

    The time passes. ** Below:

    Define the name variable in the form2 form to store the value that is passed in:

    string name;

    The following describes how to construct a string parameter in form2:

    public form2(string name);Stores the values that come in.

    Assuming you have obtained the value of name2, call the **: of form2 in form1

    form2 f2=new form2(name);Generate the form2 form and pass the value you want to pass through.

    The form2 form is displayed.

    Hides the current form, which is the form1 form.

  2. Anonymous users2024-02-04

    The following is the ** in Form 1.

    public string str="";Define a global variable in form1.

    public string str defines the property.

    getset

    Change the value of str in form1.

    Here's the ** in form2.

    form1 f1=new form1();instantiate form1; The form1 form is displayed.

    string s= ;Got the value of the value str in form1.

  3. Anonymous users2024-02-03

    name2 is public static string name2;

    form1 is added to the form2 call.

  4. Anonymous users2024-02-02

    Hello, you use it in every window.

    form1 frm = new form1() creates an object for another window. It is equivalent to initializing a new object, and it cannot retain all the previous information. Initialize all the members in the constructor, if you want to do this.

    A form2 object can be defined in form3.

    form2 object.

    This way. If you just want to pass a string, you can use a similar method.

  5. Anonymous users2024-02-01

    Children's boots, you first have to understand what is object-oriented? This question is just known.

    Your question is not clear, but I think you are using a new object, and you can't get the value of the previous object if you want to. You can describe the problem clearly.

  6. Anonymous users2024-01-31

    With vs development is to follow **, if something goes wrong, it's with the program, look at the actual current value.

  7. Anonymous users2024-01-30

    Aren't you defining a string in form2, you should use form1 frm=new form1() in form2; Then pass the string as an argument, i.e. form1 frm=newform1(string s);

  8. Anonymous users2024-01-29

    Solution 1: Directly pass the value to the form2 constructor.

    Public partial class form1 : form} Solution 2: Pass the value directly to other methods or properties of form2 public partial class form1:

    Option 3: Set some data of form1 to public, and pass form1 to form2

    public partial class form1 : form}

  9. Anonymous users2024-01-28

    form2 creates a new constructor with parameters, instantiates form2 in form1, and passes the arguments through, in a word: the value is passed through the constructor.

  10. Anonymous users2024-01-27

    It is possible to define a global variable in a public class public string str;

    Then get the value in from2.

  11. Anonymous users2024-01-26

    Method 1: Pass the value (1) by writing the attribute for the form class, and write the attribute private string str in the form (here form2) class of the form to be passed; The private variable defined by public string str is a property defined in the form form2.

    Read. set write.

    2), in form2, assign the read attribute to the textbox1 text box in form2 private void form2 load(object sender, eventargs e) 3), write the following in the click event of button1 in form1** private void button1 click(object sender, eventargs e)

    Done, running on your machine, is it a success?

    Method 2: Pass the value (1) by writing the constructor for the form class, write its constructor in the form (here form2) class of the value being passed, note that the original constructor should not modify it, we can add the following directly in the **block**. string str1, str2;Define two private variables public form2(textbox tb1, textbox tb2) Define the constructor, tb1 and tb2 correspond to textbox1 and textbox2 in form1, so that the values can be passed.

    else} (2), write the following in the click event of button1 in form1** private void button1 click(object sender, eventargs e) At this point, the second method is also completed, don't you think it's very simple?

  12. Anonymous users2024-01-25

    Define a static variable in form1, assign a value to it in form2, and then assign the variable to the text box in form1.

  13. Anonymous users2024-01-24

    In form1, you instantiate form2 and pass yourself over as follows.

    form1**.

    form2 f2 = new f2();

    The regiment is like a mountain" has passed on to itself.

    Then write a showf2 method yourself in form2.

    **:in form2

    void showf2(form1 form1) rubber parameter is a form1 type parameter.

    Show yourself out of the collapse first.

    Here you can use form1.

  14. Anonymous users2024-01-23

    1.Define public string name = in form1"zhang"

    2.Create a form1 object in form2, form1 f = new form1(); Then you can pass the value.

  15. Anonymous users2024-01-22

    There are two ways to do this:

    1. Add the fname attribute to form2.

    2. Use the show method overloaded to form2 to add the passing parameters, which are explained as follows:

    Method 1form2

    private string m_fname="";

    public string fname

    set}form1

    form2 frm = new form2();

    Method 2: form2

    private string m_fname="";

    public void show(string fname)form1

    form2 frm=new form2();

  16. Anonymous users2024-01-21

    form1**.

    string name="fsdf";

    form2 f2 = new form2(name);

    this;form2:

    string name;

    public form2(string name) will then pass the name from form1 to form2.

  17. Anonymous users2024-01-20

    Overload the constructor of form2.

    By instantiating the constructor with parameters, pass the name to form1**:

    string name=“zhang”;

    form2 frm = new form2(name);

    form2**:

    string name;

    public form2(string name)

  18. Anonymous users2024-01-19

    In form2, overload the constructor and write a constructor with arguments. Instantiate the constructor with arguments in form1, and pass the value of name to the constructor in form2.

  19. Anonymous users2024-01-18

    As long as you make sure that form1 has received the value, you can close the form2 form.

    In form2, when you click button2, write = before closing the form;

    Then, when form2 is called in form1.

    form2 frm2 = new form2();

    if ( ==

  20. Anonymous users2024-01-17

    First of all, you write this in form2 when you click button2 before closing the form.

    Then, when form2 is called in form1.

    form2 frm2 = new form2();

    if ( ==

  21. Anonymous users2024-01-16

    You can do this.

    Form 1namespace dd5

    private void button1_click(object sender, eventargs e)}}

    Then call this str in form 2 and you're good to go.

  22. Anonymous users2024-01-15

    It's not a good idea to use static classes or global members.

    Is there a connection between your form2 and form1? For example, does form2 appear after clicking a button in form1 or something else?

  23. Anonymous users2024-01-14

    You can use static variables in the global class, or you can use parent-child forms.

  24. Anonymous users2024-01-13

    The best way to do it. Let's use the commission with the event.

Related questions
8 answers2024-02-09

Your anomaly was triggered, but it was eaten.

Because the using statement is actually try....Finally, your ** is equivalent to. >>>More

10 answers2024-02-09

According to the Pythagorean theorem: ab 2 = bc 2 + ac 2 gives 13 2 = 5 2 + ac 2 solution gives ac = 12 >>>More

7 answers2024-02-09

C2 embodies a new urban lifestyle of life and nature C2 is positioned for vitality. >>>More

8 answers2024-02-09

<> the second step, enter the faction.

<> Step 4: After logging in successfully, select the family below. >>>More

27 answers2024-02-09

You can pass the main window as a parameter to a child window. >>>More