Click here to Skip to main content
15,881,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to show a second form, that shows detail data on a certain position, and the second form should hide a control on the mainForm.

The subForm loads with the correct size but not on the expected position.

Any ideas how to realize my plan?

What I have tried:

SubForm.Show()
SubForm.Size = Me.childView.Size
SubForm.Location = Me.childView.Location
Posted
Updated 9-Nov-20 23:43pm

Try setting the location before you call Show, and check that the Location you are setting it to is relative to the screen, not the existing form. If you want it relative to a form, you need to add that forms top-left coordinates to the child control Location before you set it.

But be aware that this probably won't work the way you want - Show is not a Modal call, so if the user clicks anywhere on your original form, the new one will lose the focus and be hidden behind the first.
Most likely, you want to use a UserControl instead of a form, if you want it to cover controls on your existing form.
 
Share this answer
 
Comments
Jo_vb.net 10-Nov-20 6:26am    
I'm happy to get answers but I wonder why my question does not appear on the main page of CP?

Me.childView is a UserControl but does not work as I would like to have it.

Parts of my demo project are taken from CP articles about Master/Detail GridViews.

But most of them have the issue with the keys not working on the childView - that prevents moving through the child grid with arrow keys.
Same happens with keys page up/down and pos1/end.

Instead of navigating through the childView those keys let you navigate through the Main/Parent Form.

There is only one without that issue - but in C# and I do not understand how the issue is fixed there:
https://www.codeproject.com/Tips/1215736/Master-Detail-Datagridview-in-Csharp

That's why I try to do the details with my own subForm.
OriginalGriff 10-Nov-20 6:39am    
It does: it's under "Questions" on the right hand side, currently second from the top.
If you are looking at the main QA page, check your filters (right hand side) and which tab you are viewing (top left).
Jo_vb.net 10-Nov-20 6:44am    
Ok, when the filter is ALL it appears.
when the filter is .NET it does not appear.
OriginalGriff 10-Nov-20 7:04am    
Because your question is tagged to "VB.NET" & "WinForms.Net" only. ".NET" is a different tag altogether.
Jo_vb.net 10-Nov-20 9:11am    
The order of the code lines does not change the resulting offset between the Me.childView position and the SubForm position.

When I add MainForm.Location + Me.childView.Location then the offset is smaller and the size is ok, but the subForm covers only parts of the Me.childView control.

This is what I have now:

SubForm.Show()
SubForm.BringToFront()
SubForm.Size = Me.childView.Size
SubForm.Location = New Point(MainForm.Location + Me.childView.Location)
If you are looking for defined location, use: FormStartPosition Enum (System.Windows.Forms) | Microsoft Docs[^]

One of the enum is manual[^] for a point location:
VB
Public Sub New()
    InitializeComponent()
    Me.StartPosition = FormStartPosition.Manual
    Me.Location = New Point(0, 0)
End Sub


About child-parent communication, you can use multiple ways - callback, delegates, properties.
 
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