Winform inside a SplitContainer Funny Behaviour


A

AnikSol

Hi,
I have a split container with the left panel having the navigation menu and
the right panel displays the required winform.

When the form is displayed inside a splitcontainer panel, the textboxes
behave a bit funny. There is no way I can have the mouse cursor placed
inside a textbox in the position I want to. The complete textbox gets
selected on entering the textbox. Also, I can only place the mouse cursor at
the extreme left of the text in the textbox.

Any ideas why this is happening.

If I run the same form outside the split container (that means the form is
not docked in the split container panel, then the textbox behaves normally.

thanks
 
Ad

Advertisements

S

Stoitcho Goutsev \(100\)

Hi,

I don't see how this can be a problem with SplitterContainer. Don't you have
the same problem without it?

The splitter container is not more than a two panels docked and separated by
a splitter inside another panel.

Can you post some sample code that demosntrates the problem.
 
A

AnikSol

Hi,

Say lets use the northwind database. create a simple form to display the
orderdetails in a "detail view".

now create a form called mainform and add a split container to it with 2
panels.
On the left panel (panel1) , say we have a tree node

On click the node, the orderdetails form is shown in the splitcontainer
panel2.
so the code would be something liek this:
frmorderdetails.toplevel = false
frmorderdetails.parent = splitcontainer1.panel2
frmorderdetails.show()
frmorderdetails.dock = dockstyle.fill

In the project properties, if you set frmorderdetails as startup form. The
textboxes behave normally.

Now in the project properties, set the mainform as startup form, then on
clicking the node , you will have the orderdetails form inside the
splitcontianer panel2.
In this case, the cursor can be placed only at the beginning of the textbox
text.

Trust could explain the scenario.

thanks.
 
L

Linda Liu [MSFT]

Hi AnikSol,

I performed a test based on your description and sample code. I did
reproduce the problem.

As what Stoitcho said, the split container is no more than two panels
docked and separated by a splitter. We could show a form in a Panel or
Group control as well. In this case, the form's behavior is just like when
it is shown in a split container.

I think this behavior is by design. I recommend you to replace the form
with a user control. I mean you could show a user control in the split
container instead of a form. Then everything will be fine.

Hope this helps.
If you have anything unclear, please feel free to let me know.



Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AnikSol

Hello Linda,

Tried with usercontrol, its ok.
If we create a usercontrol derived from the existing winforms, it just
behaves the way it was before - ie, the cursor can only be added at the
beginning of the text.

But to convert atleast 40 winforms into user controls and change the coding
etc, its going to be a gigantic efforts.
Secondly, my changing the whole application to an MDI also is causing a few
other headaches.

Is there any work around for this ?

regards
 
A

AnikSol

Hello Linda,

Since all the textbox controls on our forms are usercontrol ( inheriting
textboxes to ensure that only numeric values are allowed)

so in the numerictextbox (userocntrol which is inheriting from textbox.) on
mouseclick event, following code was written


Private Sub NumericTextBox_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick

Me.SelectionStart() = (e.Location.X) / 6

Me.SelectionLength = 0

End Sub

In the above code, if we used only e.location.x, the cursor was being placed
very far of from click point, so by hit and trial, got the e.location.x/6

Though it is working, but not very sure if this is the right way.

trust you could advise.

regards
 
L

Linda Liu [MSFT]

Hi AnikSol,
If we create a usercontrol derived from the existing winforms, it just
behaves the way it was before - ie, the cursor can only be added at the
beginning of the text.
Could you tell me what you mean in the above sentence? I don't think we
could have a usercontrol derived from a form.
But to convert atleast 40 winforms into user controls and change the
coding etc, its going to be a gigantic efforts.
You could almost copy the child controls and the code in the winform into a
usercontrol and only need a little modification.
my changing the whole application to an MDI also is causing a
few other headaches.
Could you tell me what the headaches are when you are trying to changing
the application to an MDI?

I have performed a test based on your sample code of setting the selection
start in the numerictextbox and it did work. However, I would say that it
may not be a formal way.

In my opinion, your problem has two workarounds. One option is to create a
usercontrol for each winform in order to show the usercontrols in the panel
of the split container. The other option is to show these winforms in a MDI
parent as MDI child.

As for the first option, as I have mentioned, it will ask for some efforts
to create a usercontrol for each winform. As for the second option, you may
use a toolstrip instead of the previous navigation menu in the left panel
within the split container and add the toolstrip onto the MDI parent. Then
you show those winforms as MDI child.

In short, if you do want to display those winforms in the right panel
within the split container and won't display those winforms outside a
container, I still recommend you to use usercontrols instead of winforms.
If you also want to show these winforms outside a container in some cases,
I recommend you to change the application to an MDI frame and add a
toolstrip instead of the previous navigation menu onto the MDI parent.

If you need our further assistance, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
A

AnikSol

Linda,

Thanks.
I think the best option is to persue the MDI way.

regards
 
L

Linda Liu [MSFT]

Hi AnikSol,

How about your changing the application to an MDI?

If you need our further assistance, please feel free to post in the
newsgroup and we will follow up with you in time.

Thank you for using our MSDN Managed Newsgroup Service!


Sincerely,
Linda Liu
Microsoft Online Community Support
 
Ad

Advertisements

G

Guest

Hi Linda

I've the same problem as AnikSol. I've tried your way of changing the app to
an MDI.

I set my main form as MDI parent and those child forms as MDI children.
However, those child forms were hidden when I called the respective child
forms by Show(). I've also tried to call those child forms by same way
without assigning those child forms as MDI children. It worked fine.

What I suspect is the MDI children forms will be hidden behind the split
container. Am I true to say that?

Thanks
 
L

Linda Liu [MSFT]

Hi,

It seems that after you set your main form as MDI parent, you didn't remove
the split container control from the main form. Right?

If so, the MDI child forms will be covered by the split container control
on the main form after they are shown, so they are not visible.

Since you have changed your main form as MDI parent and child forms as MDI
child, why not remove the split container control from the main form?

Hope this helps.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
L

Linda Liu [MSFT]

Hi,

I suggest that you add a TreeView control on the MDI parent and dock the
TreeView control to its parent's left side.

If you'd like the MDI child to take up the rest space in the MDI parent,
you could set the its Location property to {0,0} in its VisibleChanged
event handler.

The following is a sample.

// Form2 is going to be shown as an MDI child
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.VisibleChanged += new EventHandler(Form2_VisibleChanged);
}

void Form2_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible)
{
this.Location = new Point(0, 0);
}
}
}

Hope this helps.
If my suggestion is not what you want, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
G

Guest

Hi Linda,

Thanks for your recommendation.

I decided to display my winforms outside the container since it shld be the
easier way to achieve what I want. Now I encounter another problem when I do
so. The winform is displayed at the top when I call it by selecting from the
menustrip. But the same winform behaved differently when I select it from the
treeview on left panel. It'll pop up and minimize very quickly. I tried to
set the topmost of the winform to be true. It works fine but the cursor won't
be focused on the field I want after the winform is loaded. I would like to
check with you that how can I do to let my winform stay at the top and the
cursor will be focused on the field I want?

Thanks
 
L

Linda Liu [MSFT]

Hi,

I performed a test based on your description and did see the same thing as
you did.

I use Spy++ to capture the treview control when the program is run. When I
select one tree node and a form is shown, WM_KILLFOCUS message is sent to
the treeview and the focus is taken from treeview to the new form. Later,
treeview receives WM_SETFOCUS message and the focus is taken back to the
treeview.

If I don't show a new form when a tree node is selected, treeview won't
receive either WM_KILLFOCUS message or the later WM_SETFOCUS message.

Thus, I find a workaround. That is to derive a new control from TreeView
and override the WndProc method to discard the WM_KILLFOCUS message. The
following is a sample.

class MyTreeView:TreeView
{
private const int WM_KILLFOCUS=0x0008;
protected override void WndProc(ref Message m)
{
if ( m.Msg == WM_KILLFOCUS)
{}
else
{
base.WndProc(ref m);
}
}

You should build the project and then add MyTreeView onto your form.

I have tried this workaround and confirm it works. The only problem of this
workaround is that when the derived TreeView control loses focus, the tree
node still has a highlight backgroud, as if it still gets focused.

Hope this helps.
If my suggestion isn't appropriate for your scenario, please feel free to
let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
G

Guest

Hi Linda

You're excellent. Really thanks for your help.

Your solution did help me solve the focus problem. However, the login form
still lost the focus when I start up the application.

I also encounter another probelm. The size of the called up subforms are
kept changing. I've set the size of all the forms to be 800x600. But the size
of forms are 'unstable' when it's loaded. Is it other way to solve the
problem besides setting the minimum size of all the subforms?

Thanks!
 
L

Linda Liu [MSFT]

Hi,

Thank you for your reply.
However, the login form still lost the focus when I start up the
application.

Is this problem related to the TreeView control?

No matter what causes this problem, I suggest that you show the login form
before the main form is initialized and loaded. You could show the login
form before the line of code 'Application.Run(new Form1());' in static Main
method in the Program class.

As for your another problem of setting the size of the child forms, only
when the form is visible, setting the form's size would take an effect. I
suggest that you set the size of the form in the form's Load event handler.

Hope this helps.
If you have any question, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
Ad

Advertisements

Joined
Nov 21, 2012
Messages
1
Reaction score
0
Can you please tell me a better way to convert C# winform to usercontrol?

Thanku !
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top