0

我正在开发一款软件,它将模拟浏览器登录,并执行一些GET请求POST,服务器有时需要访问用户输入的校验码。

所以我制作了一个表单让用户输入校验码但是当我尝试将参数传递到校验码表单时,它无法将值设置为用户在文本框中输入的值。

这是代码CheckcodeForm.cs

public partial class CheckcodeForm : Form
{
    public string pic_url;
    public string ck;

    public CheckcodeForm()
    {
        InitializeComponent();
    }

    public CheckcodeForm(string _ck,string pic_url)
    {
        InitializeComponent();
        this.pic_url = pic_url;
        this.ck = _ck;
        pictureBox1.ImageLocation = pic_url;      
    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        this.pictureBox1.ImageLocation = pic_url;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.ck = this.textBox1.Text;
        this.Hide();
    }
}

这是新的CheckcodeForm部分:

string _check_code = "0000";
new CheckcodeForm(_check_code,checkcodePicUrl).ShowDialog();                       
MessageBox.Show(_check_code);

为什么我总是收到 0000 的消息框?

4

1 回答 1

2

您正在将文本框值分配给ck表单中的字段,因此从那里获取它:

string _check_code = "0000";
var checkcodeForm = new CheckcodeForm(_check_code,checkcodePicUrl).ShowDialog(); 
MessageBox.Show(checkcodeForm.ck);

顺便说一句,您是按值传递参数,而不是按引用传递。检查传递参数(C# 编程指南)

于 2013-08-09T01:44:04.720 回答