正在链接我的.cs文件
本文关键字:cs 文件 我的 链接 | 更新日期: 2023-09-27 18:26:53
由于使用一个巨大的转变声明,我不想让人们费力了解发生了什么。问题是txtresponse描述在我的应用程序中写入的文本框的命令不是定义在新文件中,我不知道为什么。这是我的新文件:
(错误:txtresponse在此当前上下文中不存在)
p.s.仅使用System.Windows.Forms;突出显示它包含所有应用程序表单,按钮和它们的作用等等…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GUI_Verify
{
class commands : Form
{
public static string call_command(string stmnt)
{
string cmd = "";
switch (stmnt)
{
case "TST_ALL":
txtresponse.Text = "'r'nTesting all memory tests.'r'n";
cmd = "1";
break;
case "TST_PKT_BFFR":
txtResponse.Text = "'r'nTest for Packet Buffer.'r'n";
cmd = "2";
break;
case "TST_XDATA":
txtResponse.Text = "'r'nTest for XDATA.'r'n";
cmd = "3";
break;
case "TST_REN_RAM":
txtResponse.Text = "'r'nTest for Retention Ram.'r'n";
cmd = "4";
break;
case "TST_CODE_RAM":
txtResponse.Text = "'r'nTest for Code Ram.'r'n";
cmd = "5";
break;
case "Copy_All":
txtResponse.Text = "'r'nCopying all memory to all places.'r'n";
cmd = "6";
break;
case "to_xdata":
txtResponse.Text = "'r'nCopying xdata -> xdata.'r'n";
cmd = "7";
break;
default:
txtResponse.Text = "'r'nunknown command'r'n";
break;
}
return cmd;
}
}
}
我以前遇到过这个问题。首先对代码进行注释,并删除表单中的txtresponse文本框。然后从工具箱中拖放一个新的textbox,并将其重命名为"txtresponce"。取消对代码的注释,希望它能正常工作。
更新:
这只是一个替代方法的建议。而不从Form类继承
使用输出参数来保存文本框的值。
namespace GUI_Verify
{
public class commands
{
public static string call_command(string stmnt, out string result)
{
string cmd = "";
switch (stmnt)
{
case "TST_ALL":
result = "'r'nTesting all memory tests.'r'n";
cmd = "1";
break;
case "TST_PKT_BFFR":
result = "'r'nTest for Packet Buffer.'r'n";
cmd = "2";
break;
case "TST_XDATA":
result = "'r'nTest for XDATA.'r'n";
cmd = "3";
break;
case "TST_REN_RAM":
result = "'r'nTest for Retention Ram.'r'n";
cmd = "4";
break;
case "TST_CODE_RAM":
result = "'r'nTest for Code Ram.'r'n";
cmd = "5";
break;
case "Copy_All":
result = "'r'nCopying all memory to all places.'r'n";
cmd = "6";
break;
case "to_xdata":
result = "'r'nCopying xdata -> xdata.'r'n";
cmd = "7";
break;
default:
result = "'r'nunknown command'r'n";
break;
}
return cmd;
}
}
}
在你的表格中,做以下操作。
string result="";
string cmd = commands.call_command("TST_ALL", out result);
txtresponse.Text = result;