如下面的FormGetAmount是窗口的构造函数里,如何保存RetAmount的引用地址,以使在Click里,更改RetAmount的值,最后在窗口退出后返回调用窗口。
C语言有取地址的用法,保存指针就可以了,C#如何完成该任务呢?    public partial class FormGetAmount : Form
    {
        public FormGetAmount(double Amount,out double RetAmount)
        {
        }
        public Button1_Click(object sender, EventArgs e)
        {
              //如何在这里更改RetAmount的值,
        }    }
----------------------------------
                FormGetAmount Form = new FormGetAmount(Amount,out Amount);
                Form.ShowDialog();
                Form.Dispose();       这里需要取Amount返回的值

解决方案 »

  1.   

    public partial class FormGetAmount : Form
        {
            private double retAmount=0;
            public double RetAmount
           {
              set {retAmount=value;}
              get { return retAmount;}
            }
            public FormGetAmount(double Amount)
            {
            }
            public Button1_Click(object sender, EventArgs e)
            {
                 retAmount=2;
                this.dialogresult=dialogresult.ok;
            }    }FormGetAmount Form = new FormGetAmount(Amount);
    Form.RetAmount=1;
    if(Form.ShowDialog()==dialogresult.ok)
    {
           messagebox.show(Form.RetAmount.ToString());
    }  
      

  2.   

    一个输入窗口,Show函数间接实现了你那个功能public partial class InputBox : Form
        {        
            private InputBox()
            {
                InitializeComponent();
            }        public String getValue()
            {
                return textBox1.Text;
            }        private void button1_Click(object sender, EventArgs e)
            {        }        public static bool Show(String title,String inputTips,bool isPassword,ref String value)
            {
                InputBox ib = new InputBox();
                if (title != null)
                {
                    ib.Text = title;
                }
                if (inputTips != null)
                {
                    ib.label1.Text = inputTips;
                }            if (isPassword)
                {
                    ib.textBox1.PasswordChar = '*';
                }            if (ib.ShowDialog()==DialogResult.OK)
                {
                    value = ib.getValue();
                    ib.Dispose();
                    return true;
                }
                else
                {
                    ib.Dispose();
                    return false;
                }
            }
        }