简体   繁体   中英

How to open the two forms at run time using C#?

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.

在此处输入图像描述

在此处输入图像描述

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

Thank you

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.

ps: 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.

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

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