Home > Software engineering >  How to open the two forms at run time using C#?
How to open the two forms at run time using C#?

Time:07-20

I have 2 forms, one of which is the keyboard and the other with the text field.

But when the forms load, the form with the text field becomes active and then I can't use the keyboard.

It's working fine with notepad.

enter image description here

enter image description here

I want to write to the text field using my keyboard.

Thank you

CodePudding user response:

You can use this code to show multiple form at the same time Assume that you run this code from button click of main form

Form1 form1 = new Form1();
Form2 form2 = new Form2();

form1.Show(this);
form2.Show(this);

The this keyword is optional, and can be removed.

p.s: I suggest use correct naming in your app to help better coding and debugging. Something like keyboardForm instead of form2 will be more readable and helpful.

CodePudding user response:

The thing was, I want to write to the text field using my own forms keyboard.

here is the code I found (mentioned by @RandRandom) and post

Thread thread = new Thread(() => Application.Run(new MainForm()))
{
  IsBackground = false
};

thread.Start();

This works because this is, not to fall the second form (keyboardForm) in the background

  • Related