当我从另一个表单调用字符串时,字符串是一个空字符串。
(Messenger) Form 2:
Facebook mainlist = new Facebook();
if (!(iurl == mainlist.currentstring))
{
iurl = mainlist.currestring; //Update the string
MessageBox.Show("success!");
}
(Facebook) Form 1:
public string currentstring{ get; set; }
信息:
我正在使用CEF3,在我的表单1中,我的应用会自动获取当前网址
private void OnBrowserAddressChanged(object sender, AddressChangedEventArgs args)
{
currenturl.Text = args.Address;
thistring = args.Address;
}
当更改了某个currenturl文本时,打开一个新表单(Messenger)
currenturl.TextChanged += (s, e) =>
{
currentinbox = currenturl.Text;
MessageBox.Show(currentinbox + " = " + currenturl.Text);
if ((currenturl.Text.Contains("https://www.messenger.com/t/") == true) & (currenturl.Text.Contains("https://www.messenger.com/t/me/") == false))
{
Process[] pname = Process.GetProcessesByName("Facebook");
if (!(pname.Length == 3))
{
Messenger inbox = new Messenger();
inbox.iurl = currenturl.Text;
inbox.Show();
browser.Back();
}
}
};
然后在我的Form2(Messenger)中自动启用一个Timer。
private void DetectUrl_Tick(object sender, EventArgs e)
{
Facebook mainlist = new Facebook();
if (!(iurl == mainlist.currentinbox))
{
string inboxme = "var els = document.getElementsByTagName(\"a\");" +
"for (var i = 0, l = els.length; i < l; i++) {" +
"var el = els[i];" +
"if (el.href === \"https://www.messenger.com/t/\"" + mainlist.currentinbox + "\") {" +
"el.click();" +
"}" +
"}";
iurl = mainlist.currentinbox;
MessageBox.Show(iurl + " = " + mainlist.currentinbox);
browser.ExecuteScriptAsync(inboxme);
}
}
但是&#34; mainlist.currentinbox&#34;为null或空字符串
答案 0 :(得分:0)
Form1中:
private void label1_Click(object sender, EventArgs e)
{
Form2 n = new Form2();
label1.Text = n.lol;
}
窗体2:
public string lol = "xd";
目前有效吗?也许你没有在你的例子中为thistring变量赋值?