Windows Develop Bookmark and Share   
 index > Windows Forms General > non-topmost form textbox behavior
 

non-topmost form textbox behavior

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

Brian Campbell  Monday, March 06, 2006 3:18 PM
Does anyone from Microsoft monitor this board? Is this a known bug? Am I doing something wrong? I've recreated this issue with a number of Forms/TextBoxes...
Brian Campbell  Monday, March 13, 2006 4:50 PM
Hi Brian, i'm experiencing the exact same problem you had with the textboxes but in a MDI context. Moving the focus to another MDI child and then returning to the window with the textbox, the problem disappears. But this isn't an acceptable workaround for me.

Were you able to solve the problem?
I would appreciate any comments you may have on the subject.

Thank you
Achenar

Achenar  Monday, May 08, 2006 4:26 PM

Yes, this is a sporadic problem with textboxes. I'm having the same problem when the textbox resides in the same container as the WEB Browser, or if the text box is 2-level deep or more when using compound user control.

JRQ  Monday, May 08, 2006 8:19 PM

You can use google to search for other answers

Custom Search

More Threads

• Textbox Tag on base class
• Add Items to All Combobox on form at once?
• Visual Interdev
• WebBrowser control - catching onchange JavaScript events
• RemoteDirectoyListing
• Closing one form from another form
• Drag and drop in listview using C#
• Scrollbar locks with styles enabled, but is fine in classic mode
• UrlEncode
• System.ObjectDisposedException: on closing mdi form.