Button visibility

Alfie Chadd 61 Reputation points
2022-02-23T15:38:34.887+00:00

Hello I am trying to create a button (home) that will make another button visible when clicked, this part of it works, after the home button is clicked again the other buttons hide, this also works. The issue is this only works ONCE.

        public Desktop()
        {
            InitializeComponent();
            LOGIN lg = new LOGIN();
            lg.Close();
            PowerButton.Visible = false;
            SignOutButton.Visible = false;
        }


        private void HomeScreen_Load(object sender, EventArgs e)
        {


        }

        private void Home_Click(object sender, EventArgs e)
        {
            PowerButton.Visible = true;
            SignOutButton.Visible = true;
            HomeHideButton.Visible = true;
            Home.Visible = false;
            Console.WriteLine("Show");
        }

        private void PowerButton_Click(object sender, EventArgs e)
        {
            PowerRestartButton.Visible = true;
            PowerShutDownButton.Visible = true;
        }

        private void SignOutButton_Click(object sender, EventArgs e)
        {

        }

        private void PowerShutDownButton_Click(object sender, EventArgs e)
        {

        }

        private void PowerRestartButton_Click(object sender, EventArgs e)
        {

        }

        private void HomeHideButton_Click(object sender, EventArgs e)
        {
            PowerButton.Visible = false;
            SignOutButton.Visible = false;
            Home.Visible = true;
        }

is there anyway to make it work more than once and preferably unlimited times?

thanks

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,821 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,204 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 24,281 Reputation points Microsoft Vendor
    2022-02-24T05:49:38.007+00:00

    @Alfie Chadd , If you want to use One button to limit the visiable of other buttons.

    You could refer to the following code to use a bool variable:

     public partial class Form1 : Form  
        {  
            public Form1()  
            {  
                InitializeComponent();  
                PowerButton.Visible = false;  
                SignOutButton.Visible = false;  
            }  
            bool t=true;  
            private void Btn_Home_Click(object sender, EventArgs e)  
            {  
                if(t)  
                {  
                    PowerButton.Visible = true;  
                    SignOutButton.Visible = true;  
                    t=false;  
                    Console.WriteLine("Show");  
                }  
                else  
                {  
                    PowerButton.Visible = false;  
                    SignOutButton.Visible = false;  
                    t = true;  
                    Console.WriteLine("not Show");  
                }  
               
             
             
            }  
      
            private void PowerButton_Click(object sender, EventArgs e)  
            {  
                //PowerRestartButton.Visible = true;  
                //PowerShutDownButton.Visible = true;  
            }  
        }  
    

    Result:

    177385-5.gif

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful