question

PatilNarayanaReddyCognizant-3509 avatar image
0 Votes"
PatilNarayanaReddyCognizant-3509 asked DanielZhang-MSFT commented

Unable to place cursor after adding textbox control in windows form and adding form to panel control

Hi,

Below are the steps to reproduce an issue.
1. Created Form1.cs
2. Added split container to Form1.cs
3. Added panel to SplitContainer.Panel2
4. Created Form2.cs
5. Added three textbox controls to Form2.cs
6. Added below lines of code

Form2 frm2 = new Form2();
frm2.TopMost = true;
frm2.TopLevel = false;
frm2.BringToFront();
frm2.Parent = panel1;
frm2.Show();

Initially cursor is at 0th position and when trying to place cursor in the middle using mouse, full text is getting selected. I am unable to place cursor on mouse click at specified position .






windows-forms
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @PatilNarayanaReddyCognizant-3509 ,
>>Initially cursor is at 0th position and when trying to place cursor in the middle using mouse, full text is getting selected.
I followed your steps and got the following situation.
116574-721.gif
Here is my code example:

 private void Form1_Load(object sender, EventArgs e)
 {
     splitContainer1.Panel1.BackColor = Color.Green;
     splitContainer1.Panel2.BackColor = Color.Red;
    
     Form2 frm2 = new Form2();
     frm2.TopMost = true;
     frm2.TopLevel = false;
     frm2.BringToFront();
     frm2.Parent = panel1;
     frm2.Show();
 }

I can't reproduce your problem, please point out the problem in my steps, or provide more detailed information to reproduce the situation.
Best Regards,
Daniel Zhang


0 Votes 0 ·
721.gif (167.3 KiB)

Maybe such unusual scenario is not designed and is not supported. Instead of Form2 you can define a UserControl. Then it can be inserted to your panel or to separate forms.

0 Votes 0 ·

Hi,

Can you please populate some text in the textbox and try.

0 Votes 0 ·
DanielZhang-MSFT avatar image DanielZhang-MSFT PatilNarayanaReddyCognizant-3509 ·

Hi @PatilNarayanaReddyCognizant-3509,
May I know whether your issue has been solved or not? If not, please share it in here. We can work together to figure it out.
Best Regards,
Daniel Zhang

0 Votes 0 ·

Hi,

The issue is resolved and still I do not why it will work for only borderless form.

0 Votes 0 ·
DanielZhang-MSFT avatar image DanielZhang-MSFT PatilNarayanaReddyCognizant-3509 ·

Hi @PatilNarayanaReddyCognizant-3509,
Since form2 is not a top-level window, the Windows window manager cannot activate the window. So set borderless (remove the subtitle bar in the form) to convert the form into a control that is indistinguishable from the user control, so that the textBox can work normally.
Best Regards,
Daniel Zhang

0 Votes 0 ·

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

Hi PatilNarayanaReddyCognizant-3509,
I reproduced the problem through your description. This happens because you are displaying a form with a title bar.
You need to remove the title bar from the form via following code:

 frm2.FormBorderStyle = FormBorderStyle.None;

More details you can refer to this thread.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.