C# Winforms launches Duplicate Instances when hit enter key

Viewed 39

Problem: When I Launch my Windows Application by clicking the desktop icon using Windows 7, and press enter key from the keyboard once the application is loaded it will open another instance of the application.

It seems that when I click the desktop icon first try and the application is launched the focus is still on the desktop icon.

This scenario doesn't happen on Windows 10 , tested it several times.

I've tried several options already such as on Shown Event and Activated Event to keep focus on the form and text box but its not working

sample code below:

    private void frmLabelPNInput_Shown_1(object sender, EventArgs e)
    {
       
        this.Focus();
        this.txtLabelS.Focus();
    }

Any idea how to resolve this issue?

is there a way to prevent windows to open a new instance when the user press enter?

1 Answers

Based on my readings online , only solution that can be made for this problem is to restrict the application from running multiple instances.

Related