简体   繁体   中英

Make the second form enable again after disabled

I just face a new problem I have one form which there is a button in it and when user click on this button another form will be appear and open. I set an events that when user double click on the second form the form will be disabled and user can't do anything when form become disabled. But i want to set a way that user can make the second form enable again. I tried some events that when user press enter on the second form the second form become enable again and this is my code :

f3.Enabled = true;

But in fact when i press enter after disable the form nothing happen at all. I tried some another way something like when user pressDown a key the second form become enable and this is my code :

f3.Enabled = true;

But something is make me angry that when the second form is open i cant do anything with the first form and i have to close the second form first. But cause of disabled i can't close the second form. what is your advice ? what events can i add or what code should i put in my program to make this way to enable and disable the second form so easily ? thanks in advance for your advice .

Update Would you please tell me how can i put some controls in one grid and disable them ? For example i don't want that user make any changes except close the form by clicking on 'x' button. Update This is my Form number 3

As you see i have 2 buttons and 3 labels which i didn't put code in labels. but i wanna when user click on start all controls in form become disabled (especially click on form : it means that user can't click on the form like when its disabled) except Exit button. And above the form 'x' Button and minimized and maximized button become enable.

Update I did this code in Form 2:

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

private void Form2_DoubleClick(object sender, EventArgs e)
{
    this.Enabled = false;
}

private void Form2_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        this.Enabled = true;
    }
}

}

And already a code that you wrote there. But i have that problem yet. I put a picture that maybe can help ya. maybe can help ya this image

Update

I tried KeyPreview in my form and changed it into true but i have that problem yet. Any advice ? It means that there is no code for my idea ?!? . Update

I tried so many code for this question and couldn't find my answer yet... let me describe better that what is my problem I have 2 forms and i wanna when user click on the second form the form become non clickable and user can't do anything when user click on that button except minimize and maximize and exit from the form. I found some codes but they didn't help me... Maybe you can :

this is my code in the button :

        private void btnStart_Click(object sender, EventArgs e)
    {
        f3.Visible = false;
    }

and i also tried this code :

        private void btnStart_Click(object sender, EventArgs e)
    {
        this.Enabled = false;
    }

And also set keypreview for this form but when i click on the button the form become Disable and i cant do anything except close the program from taskbar. any advice ?

You can do it something like this for forms:

Form1:

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

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 frm = new Form2();
        frm.ShowDialog();
    }
}

Form2:

// on form, set form property KeyPreview to true
public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_DoubleClick(object sender, EventArgs e)
    {
        this.Enabled = false;
    }

    private void Form2_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            this.Enabled = true;
        }
    }
}

If you want to do with grid view or something, you can enable/disable grid in the same way.

Please let me know if you have further questions.

I hope it will help you.. !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM