Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4051982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:15:46+00:00 2026-05-20T14:15:46+00:00

i have a Form which has a button, on the button click event, a

  • 0

i have a Form which has a button, on the button click event, a variable locklogin is increased by 1

when locklogin =3 , then the form button gets disabled and the form needs to be closed.
on closing the form , locklogin loses its value.

but i want to hold its value albeit the form being closed and when the form is run again(the whole application is executed again), then the button is still disabled. how do i do this?

 public partial class Form1 : Form
{
    static int loginlocked;
    static int isloginlocked;
    public Form1()
    {
        InitializeComponent();

        if (isloginlocked == 3)
        {
            foreach (Control c in this.Controls)
            { c.Enabled = false; }

        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        loginlocked++;
        if (loginlocked == 3)
        {
            foreach (Control c in this.Controls)
            { c.Enabled = false; }

            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);

        }
    }
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        isloginlocked = loginlocked;
        if (e.CloseReason == CloseReason.UserClosing)
        {

            if (MessageBox.Show(this, "Really?", "Closing...",
                 MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
                == DialogResult.Cancel) e.Cancel = true;
        }
    }
}

i want that when the form/application is opened then first it checks whether the value of the variable is =3 , and if its 3 ,then it should disable the button on it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:15:47+00:00Added an answer on May 20, 2026 at 2:15 pm

    I would start thinking about separating your logic from your UI. There are various ways of achieving this and I’ve included a few links to get started.

    I would have a Controller or Presenter object listening for an event from your form when the button is clicked. This Controller object maintains the counter and is responsible for creating and destroying the form and setting initial values during construction such as whether or not a button is disabled. The form can be as dumb as possible and not have to worry about such business logic.

    Model-View-Controller

    Model-View-Presenter

    Some discussion and examples

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which has a lot of SELECTs. For various reasons, I'd
I have a ASP.NET page which has a form on it. It also has
I have an ASP.NET page which has a script manager on it. <form id=form1
I have a form on which I use validation. This form has a section
I have a form in MS Access which has an image. The image has
I have a form which is used to insert/display and update . In the
I have a form which takes both the user details and an image uploaded
In my Rails app, I have a form which redirects through a foreign service,
I have a form in which people will be entering dollar values. Possible inputs:
I have a form in which the user can choose a component type from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.