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

  • SEARCH
  • Home
  • 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 8292945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:39:33+00:00 2026-06-08T13:39:33+00:00

I created two forms: a login form, and a main form that is displayed

  • 0

I created two forms: a login form, and a main form that is displayed when I start debugging.
when loading the main form the login form also loaded.
Now my question is, I want to disable the main form when the login form is loaded.
if the connection is successful, the main form must be enabled, otherwise it should be disabled.

I tried this code :

MainFrm .cs :

private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
c.Enabled = false;
Connectez ConnectezFrm = new Connectez { TopMost = true, Owner = this };
ConnectezFrm.Show();
}

Connectez.cs :

private MainFrm objMainfrm { get; set; }
public Connectez(MainFrm objfrm)
{
objMainfrm = objfrm;
InitializeComponent();
}
....
....
private void simpleButton1_Click(object sender, EventArgs e)
{
foreach (Control c in objMainfrm.Controls)
c.Enabled = true;
this.Close();
}
  • 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-06-08T13:39:34+00:00Added an answer on June 8, 2026 at 1:39 pm

    You don’t need to disable individual controls on a form to disable the form. You could use

    objMainForm.Enabled = false;
    

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.enabled

    However, what you really want to do in your case is just show a modal dialog. Use

    ConnectezFrm.ShowDialog();
    

    Modal dialogs prevent interaction with their parent while they are active.

    Also it looks like you tried to achieve this by passing a reference to your main form to the child form:

    public Connectez(MainFrm objfrm)
    

    That is not necessary to get a modal dialog effect.

    If you need to take some action if the connection fails, you can return a DialogResult from Connectez. Check that DialogResult like this:

    DialogResult dr = ConnectezFrm.ShowDialog();
    if (dr != DialogResult.OK) {
        // Do something e.g. disable certain parts of the form
        // Be sure to leave a button or something enabled to load ConnectezFrm again :-)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two forms in my Windows Application. One Form acts as a
I am trying to do the login form I have created two uitextfields for
My page has two forms. One is a normal login form, the other is
I created two dropdpwn calendar in my form with these codes: <script type=text/javascript src=http://code.jquery.com/jquery-latest.js></script>
I created two classes in netbeans;One of them is a JPanel form and another
I want to create a view that contains two forms with their submit buttons.
I've created two UserControls, a ValidationManager and a ValidationOutput. On a given form there
I have created a form on which two components are present, button and progressbar
I have two applications Web Socket and Web Service created in .Net/Web Form and
i want to create a form that has two submit buttons, but each one

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.