【发布时间】:2023-04-01 23:10:01
【问题描述】:
我有两个表单.. Form1.cs 和 TwitchCommands.cs
我的 Form1.cs 有一个全局变量
public string SkinURL { get; set;}
我希望该字符串成为 TwitchCommands.cs 中文本框的值
这是 TwitchCommands.cs 中的代码,应该在 Form.cs 中设置公共字符串“SkinURL”
private void btnDone_Click(object sender, EventArgs e)
{
if (txtSkinURL.Text == @"Skin URL")
{
MessageBox.Show(@"Please enter a URL...");
}
else
{
var _frm1 = new Form1();
_frm1.SkinUrl = txtSkinURL.Text;
Close();
}
}
这是 Form1.cs 中尝试访问字符串“SkinURL”的代码
else if (message.Contains("!skin"))
{
irc.sendChatMessage("Skin download: " + SkinUrl);
}
假设 txtSkinURL.text = "www.google.ca" 我在 Form1.cs 中调用命令
它返回“皮肤下载:”而不是“皮肤下载:www.google.ca”
有人知道为什么吗?
【问题讨论】:
-
因为您正在创建 Form1 的新实例。具有自己的 SkinURL 变量的实例,当然该变量还没有收到您对 Form1 的第一个实例所做的更改
-
那么我将如何访问 SkinURL 变量?
标签: c# .net string methods public