0
我在我的程序中创建了一个帮助部分,并且尽量使用我拥有的编码知识时尽可能高效。如果我按如下方式输入Help.whichHelp(some_int_here);
,我已经设置了一个方法。所有这些代码都在一个文件中,Help.cs
。但标签并没有改变,即使没有其他代码,但这应该改变标签。在静态上下文中更改标签的文本
public static void whichHelp(int index)
{
int allowedCount = 0;
foreach (string namesX in HWLib.Variables.helpDir)
{
allowedCount++;
}
if (index > allowedCount)
{
MessageBox.Show("Index " + index + " does not exist!");
}
else
{
if (index == 0) Login();
}
}
这里是上面提到的“登录”方法,如果指数为0
public static void Login()
{
Help.getContent("Log In", "In order to use this program, you need to be able to log in. " +
"This is so we can track how many users we have. It also provides many user benefits to you! " +
"\n\n To login, use the username and password provided when you signed up on the website. " +
"if you did not signup, you should do so by clicking the \"SignUp\" button on the login screen.");
}
这里是获取内容
static void getContent(String header, String body)
{
if (header == null || body == null)
{
MessageBox.Show("Error loading contents of program");
Application.Exit();
}
else
{
//Since "this" isn't valid for an identifier in static context
Help thisI = new Help();
thisI.headerLabel.Text = header;
thisI.bodyLabel.Text = body;
}
}
你忘了问一个问题 –
没有任何更多的信息,我认为答案是“在这种情况下不要使用静态” – vcsjones
对不起,我陷入了这篇文章:) – user2678408