在控件事件下是有效果的:
private void pictureBox1_Click(object sender, EventArgs e)
{
duowan dts = new duowan();
pictureBox1.ImageLocation = dts.GetCodeUrl();
}
但是在其它類中卻沒有任何反應:
if (_result.IndexOf("驗證碼") == -1 && _result.IndexOf("錯誤") == -1)
{
callbackURL = BetWeen(result.Html, "URL\":\"", "\",", 0);
}
else
{
callbackURL = "error";
string codeUrl = GetCodeUrl();
Form1 image = new Form1();
image.pictureBox1.ImageLocation = codeUrl;
}
初學C#,請各位賜教。謝謝!
Form1 image = new Form1();
你這裡創建了一個新的Form1,而不是你原來的Form1了,後面的操作就無效了。
你可以用
Form1 image = Application.OpenForms["Form1"] as Form1;
得到打開的Form1