简体   繁体   English

C#将值从结束表单传递到加载/显示表单

[英]C# Passing value from a closing form to a loading/show form

I've been trying to pass a value from a closing form to a form that is about to load. 我一直在尝试将值从结束表单传递给即将加载的表单。

Let's say I have two forms. 假设我有两种形式。 When I hide() Form1 the value from a textBox should be carried over to a variable/constructor in Form2 when I Show() it. 当我hide()Form1时,当我Show()时,来自textBox的值应被带到Form2中的变量/构造函数中。

My code is in a different laptop and I can't copy it now so I can't post it here. 我的代码在另一台笔记本电脑中,现在无法复制,因此无法在此处发布。 An example would be nice. 一个例子会很好。

To send some value to a other form you can use "where AccommodationInfo is the form you want to open and MName is the value you want to send" this code to open the form and send the value with it. 要将某些值发送到其他表单,可以使用“其中AccommodationInfo是要打开的表单,而MName是要发送的值”此代码打开表单并随其发送值。

        AccommodationInfo AI = new AccommodationInfo();
        AI.TextBoxValue = MName;
        AI.Show();

Then in the form that needs to get the value you use "where HouseNameComboBox is the location where the value will be set" this code to get and set the value. 然后,在需要获取值的形式中,使用“其中HouseNameComboBox是将设置该值的位置”的代码来获取和设置该值。

    public string TextBoxValue
    {
        get { return HouseNameComboBox.Text; }
        set { HouseNameComboBox.Text = value; }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM