Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi, all!

I have a problem with TextBoxes in my form.

Screenshot as picture http://rghost.ru/5011999/image.png

Let's show the situation on a simple example.

1) Create a new winforms project with Form1;
2) Create a new Form2, put TextBox control onto it;
3) Let's write simple code that creates the non-modal form;

MIDL
Form frm = new Form();
frm.StartPosition = FormStartPosition.CenterParent;
frm.TopLevel = false; // here is the problem
frm.Parent = this;
frm.Show();
frm.BringToFront();


Once you execute this code, the form with textbox will appear.
Type something in textbox, e.g. "this is a test". Now, try to select a part or a whole text with mouse - you can't, 'cause it doesn't work.

Yes you can select the whole text with double click, but you can't deselect it after that. Besides, what if you need to select only a part of the text to erase it?!

When the form is modal everything works fine.

The same situation for Memo and I suppose for some other text controls.

All this I need because we use serious MDI project, and inside each MDI form user can open different forms (e.g. search form). Of course, we can make 'em modal, but this won't be the real MDI from that point.

Any sugesstions, please?
Posted
Updated 1-Dec-20 13:17pm
v3
Comments
leon_saks 31-Mar-11 6:00am    
Sir, I'm completely understand the MDI and all I'm doing about.

The question was not about MDI, but why I can't select text in TextBox with mouse.
leon_saks 31-Mar-11 6:44am    
Thanks for the answer, but if I set frm.MdiParent instead of frm.Parent, the form will be connected to the Main MDI form (MDI parent), but I need to "link" the form to MDI-child.
Please, refer to the screenshot http://rghost.ru/5011999/image.png
Michel [mjbohn] 31-Mar-11 8:17am    
Let me try to get things sorted.
Form1 (your main app) is MdiContainer.
Form2 is MdiChild of Form1.
The form with the "buggy" textbox (let's call it Form3)is another form which is *not* MdiChild of Form1.
Is this correct so far?
leon_saks 31-Mar-11 8:20am    
Yes, that's abosolutely correct.

That "buggy" form (let it be Form3) is just a form that it's not MdiChild of Form1, it's a child of Form2 (which is MdiChild of Form1).

And that Form3 has TextBox with text user can't select with mouse.
Michel [mjbohn] 31-Mar-11 9:01am    
I could exaclty reproduce this behaviour of the textbox.
But I have no idea how to solve this, yet.

Replace Parent with MdiParent:

Form2 frm = new Form2();
frm.StartPosition = FormStartPosition.CenterParent;
frm.TopLevel = false;
frm.MdiParent = this;
frm.Show();
frm.BringToFront();


And make sure your main form has IsMdiContainer set to true.

---------------

Don't blame us because you didn't explain your problem properly:
If I understood well from your comments you have 3 forms:
1- MainForm with IsMdiContainer set to true
2- ChildForm with MdiParent set to MainForm
3- AnotherChildForm. And you want this one to be a child of ChildForm.

If this is correct, then you can't get rid of the bug. To remove the bug ChildForm should be both MdiContainer and MdiChild which is not possible. You must either make the 3rd form a child of MainForm, or not use a form (maybe a UserControl or something).
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 31-Mar-11 15:15pm    
No wonder you got 1 for this answer, because it's one of the best.
On this page, the better the answer, the worse the vote. It tells something.
My vote is 5.
I would insisting that MDI should not be used (OP has not idea how it works anyway), but I cannot hope my advice to be attended.
--SA
Olivier Levrey 1-Apr-11 4:02am    
Thank you SA.
First, what are you trying to accomplish by setting TopLevel to false? And why are you calling BringToFront()? When you create a modeless form, it automatically shows up (it's brought to the front).

Second, it sounds like you don't quite understand the nature of a MDI application, nor the interrelationship between child windows and other forms.

Third, if you're creating a modeless window, It should be done something like this:

C#
public partial class MyForm
{
    MyModelessForm m_modelessForm = null;

    private void ShowModelessForm()
    {
        if (m_modelessForm == null)
        {
            m_modelessForm = new ModelessForm();
            // configure the form here if necessary
        }
        m_modelessForm.Show();
        m_modelessForm.BringToFront();
    }
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-Mar-11 15:14pm    
No wonder you got 1 for this answer, because it's one of the best.
On this page, the better the answer, the worse the vote. It tells something.
My vote is 5.
I would support this by insisting that MDI should not be used (OP has not idea how it works anyway), but I cannot hope my advice to be attended.
--SA
#realJSOP 30-Oct-18 5:49am    
I got another 1-vote today - almost 8 years after I posted the answer... SMFH
Assuming you set the property IsMdiContainer of Form1 to true, your code should read like this:
Form2 frm2 = new Form2();
frm2.MdiParent = this;
frm2.Show();
 
Share this answer
 
v2
Comments
leon_saks 31-Mar-11 6:03am    
Sir, thanks a lot, but I know all this.

I'm askin' about TextBox in form that is created. This form is child of MDI-child.
Olivier Levrey 31-Mar-11 7:39am    
This answer doesn't deserve a 1. It is the good answer actually. The bug with the text box will disappear if you follow mjbohn's advice.
Have my 5 mjbohn.
leon_saks 31-Mar-11 7:45am    
This's a good question, but it's obviously. Otherwise, my MDI application wouldn't be an MDI application at all. The question was other, about TextBox. It's very important for users.

It seems nobody understand what do I do. I have MDI-child form inside MDI-parent (with IsMdiContainer turned). Inside MDI-child I have another form, that can't have another parent, but MDI-child.
Olivier Levrey 31-Mar-11 8:25am    
Don't blame us because you didn't explain your problem properly...
I updated my answer if you want to have a look. But what you want is just not possible.
leon_saks 31-Mar-11 8:38am    
Yeah, maybe you're right, I've not explained well.
And I don't blame anyone. Thank you for your patience and for the advice.
I'll try to use something like UserControl or maybe groupbox. But in this case I will need to drag it by it's header. Hm, yeah, that's the problem.
Try setting the FormBorderStyle property of the child form to 'none'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900