我一直在从我的c#课程中进行锻炼,而且我没有让它工作,这是实际的任务:
创建名为" LoginPasswordUserControl"的用户控件。 " LoginPasswordUserControl" 包含一个标签(loginLabel),显示字符串"登录:",一个文本框(loginTextBox),其中 用户输入登录名,标签(passwordLabel),显示字符串"密码:", 最后,用户输入密码的文本框(passwordTextBox)(不要忘记设置 属性Passwordchar到" *"在TextBox的“属性”窗口中)。
LoginPasswordUserControl必须提供Public只读属性 允许应用程序检索用户输入的登录名和密码 来自loginTextBox和passwordTextBox。
这是LoginPasswordUserControl代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoginApp
{
public partial class LoginPasswordUserControl : UserControl
{
public LoginPasswordUserControl()
{
InitializeComponent();
}
public string Login
{
get
{
return loginTextBox.Text;
}
}
public string Password
{
get
{
return passwordTextBox.Text;
}
}
}
}
以下是应用程序的代码,我收到错误消息: 名称' myLogin'在当前内容中不存在
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UserControlTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void OK_btn_Click(object sender, EventArgs e)
{
if (myLogin.Login != "" && myLogin.Password != "")
{
displayLabel.Text = "The information entered is:";
loginLabel.Text =
"Login: " + myLogin.Login;
passwordLabel.Text =
"Password: " + myLogin.Password;
}
else
displayLabel.Text = "Enter information above";
}
}
}