[英]How do I fix “The name 'page' does not exist in the current context”
[英]How can i fix the 'myLogin' does not exist in the current content?
我一直在通過C#課程做運動,但是我沒有使它起作用,這是實際的作業:
創建一個名為“ LoginPasswordUserControl”的用戶控件。 “ LoginPasswordUserControl”包含一個顯示字符串“ Login:”的標簽(loginLabel),一個用戶輸入登錄名的文本框(loginTextBox),一個顯示字符串“ Password:”的標簽(passwordLabel),最后是一個文本框(passwordTextBox)用戶輸入密碼的位置(不要忘記在TextBox的“屬性”窗口中將屬性Passwordchar設置為“ *”)。
LoginPasswordUserControl必須提供公用的只讀屬性Login和Password,允許應用程序從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";
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.