views:

80

answers:

1

I'm building a C# WinForms program, and my textboxes do not allow the user to highlight the text consistently throughout the program.

In some places, the highlighting works normally: you type something in the box, click and drag over some text, and it highlights where you dragged.

In other places, clicking and dragging does not select the text. The only way to do it is by double clicking on the text.

I haven't changed any default properties of these textboxes or messed with any event listeners. I placed brand new textboxes in different places, and they behave differently.

I'm wondering if it has something to do with the properties of the Form the TextBox is contained in, since it seems to appear that either all textboxes in a particular form work, or none do. However, as far as I can tell the properties look to be the same across the board, and I don't ever remember changing anything.

To me it seems like it's happening randomly. I can't find any information on the topic. Does anybody have any idea what I'm talking about?

EDIT: Ok, I figured out where the problem lies, but I still don't know how to fix it.

It happens only in forms which have been added to a SplitContainer in my main window like so:

myForm.TopLevel = false;
this.splitContainer.Panel2.Controls.Add(myForm);
myForm.Show();

EDIT 2: I now know that this is the same issue encountered here: http://stackoverflow.com/questions/2875075/windows-forms-unable-to-click-to-focus-a-maskedtextbox-in-a-non-toplevel-form . The accepted answer isn't useful to me, and the other answers seem impractical, since I'd have to add event handlers to every single textbox...

A: 

I'm a little perplexed at what you're trying to accomplish. I'm used to using a user control if I want to embed something on a SplitPanel, and using an MDI form if I want child forms.

Do either of these approaches work for you, and if not, can you explain why not/what you are trying to accomplish?

Thanks! James


* Edit *

You can add a panel (regular panel, not a split panel) to an MDI parent form and dock it to the left. Add whatever you currently have in the left panel of the SplitContainer to this left-docked panel, instead. Now you can instantiate forms, set them as children to the main MDI parent, and have all the window functionality you're looking for... You can maximize them, and they will fill the right-side of the MDI parent; you can pick cascade or tile from the window menu, etc.

If you want to let the user dynamically resize the left panel, drop a splitter panel into the right-hand portion of the main MDI form container; it will dock left by default, and show up to the immediate right of the panel. Now when you run, you can drag the border of the panel to resize.

Remember, an MDI form is like any other form... you can add any control you want to its surface, and .NET is pretty smart about how it incorporates the child windows.

If you're still not sure of what I'm trying to describe, I'll try to find somewhere I can drop a sample project... because everything is really done in the designer, there's not really any code I can show you. Here's the code for creating a form as an MDI child (running from within the MDI parent):

MyForm frm = new MyForm();
frm.MdiParent = this;
frm.Show();

That's all there is to it.

HTH! James

James B
Basically, what I would like to do is similar to using an MDI form in order to have child forms. However, I don't want to add my child forms to a parent Form, but rather a SplitContainer (my children need to be opened only in the right-side panel, and I have other things going on in the left-side panel). SplitContainer doesn't have an IsMdiContainer property, but I was able to make it act similarly by setting the top level of my children to false, and adding them to the SplitContainer (as in the code in the original question). But, this causes my problem. Any ideas?
recoisiche