Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

Controls not working (sometimes)

$
0
0

Hi. I'm really confused so I'm hoping someone can help me out here. I'm working on a programming assignment for uni but there's one part that's really been bugging me and I can't move on until it is fixed. I have created two classes. The problems in each are shown here:

class Login : Form1
    {
        Form1 f = new Form1();

        public void LoginCorrect()
        {
            Form1.attempts = 3;
            MessageBox.Show("Correct Credentials Entered!");

            f.loginScreenVar = false;
            f.mainScreenVar = true;
            f.ChangeScreen();
        }
     }

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void ChangeScreen()
        {
            //Login Screen
            txtUsername.Visible = loginScreenVar;
            txtPassword.Visible = loginScreenVar;
            btnLogin.Visible = loginScreenVar;
            lblLoginCaption.Visible = loginScreenVar;
            lblUsername.Visible = loginScreenVar;
            lblPassword.Visible = loginScreenVar;
            //Main Screen
            lblWelcomeUser.Visible = mainScreenVar;
            btnViewDetails.Visible = mainScreenVar;
            btnViewAccounts.Visible = mainScreenVar;
            btnLogout.Visible = mainScreenVar;

            MessageBox.Show(loginScreenVar.ToString());
        }
    }

I have some controls on screen in my design which consist of text boxes, labels, and buttons, and these are meant to show and hide at diffferent times. I have created some booleans which can be set to true and false which will also set the visibility of these controls to true and false.

My problem is when accessing ChangeScreen() from my Login class, for some reason the controls don't hide when they're meant to. I've literally got a message box in the ChangeScreen() method which outputs the result of 'loginScreenVar' and this is false. Please can someone tell me why my 'Login Screen' controls are NOT hiding even though 'loginScreenVar' = false.

Another thing to note is when calling this code from a button in the Form1 class, it does work. However, due to the brief of my assignment I need to use multiple classes.

I really hope this isn't a bug and someone can help me here because I literally can't move on until this is fixed, thanks!


Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>