gpt4 book ai didi

c# - 如何在 C# 中创建返回语句以打开 wpf 窗口

转载 作者:太空宇宙 更新时间:2023-11-03 10:48:39 24 4
gpt4 key购买 nike

我是这个堆栈溢出的新手,所以这是我的第一个问题。

我做了一个返回语句,所以如果这个验证返回 1,它将打开一个新窗口,否则,它不会被打开。这是我的代码:

private int UserPassValidation()
{
if (txtUserName.Equals("admin") && txtPassword.Equals("admin"))
{
return 1;
}
return 0;
}

private void LOGIN_BUTTON_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (UserPassValidation() == 1)
{
try
{
WindowView objWindowView = new WindowView();
objWindowView.ShowDialog();
}
catch (System.Data.EntityException)
{
MessageBox.Show("Entity Exception", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
else
{
MessageBox.Show("...");
}
}

因此,有一个“用户名和密码验证”和登录按钮。然后,我也在 txtusername 和 txtpassword 上插入“admin”。

然后,当我点击登录按钮时,它不会被打开。我不知道为什么,但它应该是打开的。

最佳答案

似乎您在 UserPassValidation 方法中的比较不正确。如果 txtUserName 是一个文本框,那么您应该对它的 Text 属性进行比较。喜欢..

if (txtUserName.Text == "admin" && txtPassword.Text == "admin")

关于c# - 如何在 C# 中创建返回语句以打开 wpf 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22369216/

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