You are creating a local variable of login form, so it will get destroyed after its scope and along with it the value of UseNam will also get lost.
You have to store it to something that is accessible at a point where you want to use it.
You can do it by following way also ( along with other ways :)
// This class is mainly used to transfer values in between different components of the system
public class CCurrent
{
// Currently logged in user
public static string UserName = "";
// Indicates to whole system whether database is Valid and connectable or not ?
public static Boolean DatabaseValid = false;
// Indicates whether we are able to connect databse or not.
public static Boolean DatabaseConnectable = false;
}
Now in your code you can do following :
frmLogin objLogin = new frmLogin();
objLogin.ShowDialog();
CCurrent.UserName = objLogin.RetUserName;
MessageBox.Show("NAME : " + CCurrent.UserName);
txtUserName.Text = CCurrent.UserName;