I have an old form that I would like to re-use, but to do this in my application I must host the form in another form. The problem is that I need it to look like the topmost form and to behave like it too.
On other forums I've found a way to make the form look like the topmost form by executing the following code:
this.form2 = new Form2();
this.form2.Location = new System.Drawing.Point(-6, -24);
this.form2.Size = new System.Drawing.Size(this.PanelForm2.Width + 12, this.PanelForm2.Height + 30);
this.form2.Anchor =
((System.Windows.Forms.AnchorStyles)(
(System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom |
System.Windows.Forms.AnchorStyles.Left |
System.Windows.Forms.AnchorStyles.Right)));
this.form2.TopLevel = false;
this.form2.Parent = this.PanelForm2;
this.form2.Show();
The panel has been added to Form1 in the standard form designer and the Location and Size manipulations hide the border and form controls (close, minimize, maximize) from the user.
The problem I'm having is with the TextBox controls that reside on Form2. I can click on them, so they aren't disabled. I can navigate the text in a TextBox using the arrows and the Home/End keys and I can put focus on the TextBox by clicking on it. The problem is that when I click on a TextBox that currently has text in it, the cursor/caret position doesn't change to where I've clicked and I cannot select part of the text by clicking and dragging over part of the text. I can however double-click a piece of text and that word becomes selected.
For instance, if I use '^' as my caret position and the text "the lazy dog" is in my TextBox and I click anywhere within the TextBox the result is "^the lazy dog". I can click until the cows come home, but the cursor/caret position never changes unless I use the keyboard to navigate or I double click on some of the text to select a whole word.
This problem is limited to the non-topmost form as I've added a TextBox to the topmost/host form and the TextBox behavior is correct in it.
Is there something that I can do to get this to work for my non-topmost form? Do I need to host the form in a different manner within my topmost form? Note that there are a lot of TextBoxes on this form and I want to duplicate this process with a number of other forms.
Thanks for any and all help that I can get with this problem,
Brian