gpt4 book ai didi

c# - 将值从 Windows 窗体传递到控制台应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 14:00:01 25 4
gpt4 key购买 nike

所以我有一个通过 Windows 窗体获取用户凭据的程序,现在通过 MessageBox 我正在显示用户输入,我想做的是将它传递到我的控制台应用程序中,这样如果用户输入然后它会在控制台应用程序中继续输入正确的凭据,我该怎么做呢?

最佳答案

您可能需要添加一个 while 循环来在控制台应用程序中查找 txt 文件。在 Windows 窗体应用程序中,您可以将成功或失败消息写入 txt 文件。 (为安全添加加密)当您写下信息时,您的控制台应用程序应该读取它并从那里继续。

Algorithm:
1.console application start
2. console app while loop until txt file detected
3. forms app show input screen
4. user enter credential
5. write success or failure into txt file
6. read txt file
7. continue based on credential result
8. Remove txt file

由于表单也在控制台应用程序项目中(我从你的措辞中假设它)你可以执行以下操作

class Program
{
public static object abc;
static void Main(string[] args)
{
//do something here if required
Form1 frm = new Form1();
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//login success do what ever on success
Console.WriteLine("Login success");
Console.WriteLine(abc.ToString());
}
else
{
Console.WriteLine("Login failure");
Console.WriteLine(abc.ToString());
//login failure
}
Console.ReadLine();
}
}

和登录表单类中的登录按钮点击事件

 private void Login_Click(object sender, EventArgs e)
{
if(true)
{
Program.abc = "any success object here";
//on successful login
this.DialogResult= System.Windows.Forms.DialogResult.OK;
}
else
{
Program.abc = "any failure object here";
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
}

谢谢,

亦森

关于c# - 将值从 Windows 窗体传递到控制台应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10951401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com