-2
저는 로그인 용으로 2 개의 폼과 로그인에 의존하는 함수를 호출하는 폼이 있습니다.다른 양식의 변수에 액세스
FORM1
public partial class Form1 : Form
{
static public string userId, userPassword;
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (Program.AllStudents.ContainsKey(userId))
{
Program.studentdata student = Program.LoginStudent(userId);
if (student.password == userPassword)
{
Form3 studentcommands = new Form3();
studentcommands.ShowDialog();
}
else
{
MessageBox.Show("Wrong username or password", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
}
else
{
MessageBox.Show("Wrong username or password", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
}
내가 다른 형태로 학생이라는 개체에 액세스하려면? 어떻게해야합니까?
검색으로 개체를 선언이 양식에 입력하는 학생의
Public property
을 선언하고Form1.Propertyname
을 사용하여 다른 사람에 액세스 할 수 있습니다 이 똑같은 질문의 수백만 복제본 중 하나. –
이것은 내가 스스로에게 물어 본 질문이며 자주 묻는 질문입니다. 가서 다른 대답을 확인하십시오. 그러나 편의상 AFAIK라는 두 가지 옵션이 있습니다. 첫째, 개체 공개, Form1.objectName에 의해 액세스하십시오. 또는 두 번째 옵션은 개체를 두 번째 폼에 매개 변수로 전달하는 것입니다. –
호기심에 반해서, 이것이 수업 과제입니까? 몇 시간 전에 같은 질문이 제기되었습니다. – Trey