I am having 3 classes. One is AuthenticateUser which let me to set and get user information such as username and password. In other class, AddEntryWindow is a WinForm in which I am trying to display content of the Password and UserName properties from AuthenticateUser. third class is another WinForm class which let me to set username and password to the AuthenticateUser class. As I try, in this simplified example, to display username and password from a WinForm class I am getting a blank message box. Also, when using another message box in AuthenticateUserWindow I am able to get the content of properties.
How can I fix this to be able to view content of the property in AddEntryWindow class? I have been staring blank for past hour on this.
Probably it's something with line: AuthenticateUser authenticateUser = new AuthenticateUser();
which create a new object. But where would it go instead?
Most likely problem in AddEntryWindow.cs
using System;
using System.Windows.Forms;
// Needed to be used with StringBuilder
using System.Text;
// Needed to be used with ArrayList.
using System.Collections;
namespace Store_Passwords_and_Serial_Codes
{
public partial class AddEntryWindow : Form
{
// Making authentication possible.
AuthenticateUser authenticateUser = new AuthenticateUser();
// Default constructor to initialize the form.
public AddEntryWindow()
{
InitializeComponent();
}
private void btnAddEntry_Click(object sender, EventArgs e)
{
MessageBox.Show(authenticateUser.UserName + authenticateUser.Password);
}
}
}
AuthenticateUser.cs
using System;
namespace Store_Passwords_and_Serial_Codes
{
class AuthenticateUser
{
private string userName, password;
public AuthenticateUser()
{
}
public AuthenticateUser(string userNamePassed, string passwordPassed)
{
this.userName = userNamePassed;
this.password = passwordPassed;
}
public string UserName
{
get
{
return userName;
}
set
{
userName = value;
}
}
public string Password
{
get
{
return password;
}
set
{
password = value;
}
}
}
}
AuthenticateUserWindow.cs
using System;
using System.Windows.Forms;
namespace Store_Passwords_and_Serial_Codes
{
public partial class AuthenticationWindow : Form
{
// Most important log in information needs to be entered
// for encrypting and decrypting binary file.
AuthenticateUser authenticateUser;
public AuthenticationWindow()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
// Closing Authentication Window form.
Close();
}
private void btnClear_Click(object sender, EventArgs e)
{
// Clearing text boxes txtUserName and txtPassword
// after Clear Form button is clicked.
txtUserName.Clear();
txtPassword.Clear();
}
private void btnAuthenticate_Click(object sender, EventArgs e)
{
if (txtUserName.Text == string.Empty || txtPassword.Text == string.Empty)
{
MessageBox.Show("Please fill both information first.");
}
else
{
// Passing the values to object AuthenticateUser.
authenticateUser = new AuthenticateUser(txtUserName.Text, txtPassword.Text);
MessageBox.Show(authenticateUser.UserName + authenticateUser.Password);
Close();
}
}
}
}
Regards.