-1

I have a TabControl oriented UI.

That means, that on my main form is a TabControl. TabPages are added dynamic in code.

Within the TabPage I show customer related informations within user controls. In one of these user controls I have a button to add a new order. The new order is shown in a form.

I don't want to show the form modal, so that an interaction with the main form still exists. My problem is, that I don't know how I can set the owner of the new order form can be set to a control.

Because, the "owner" property only accepts types of Forms. But when I set the owner to the form, then the order form is visible on all tab pages, what I don't want.

Dim locNewOrderForm As New frmOrderForm
locNewOrderForm.Show
locNewOrderForm.BringToFront()
' This isn't correct… 
' Here I am searching for a solution
locNewOrderForm.Owner = Me.FindForm
Zero-G.
  • 45
  • 10
  • If I well understand you need to set A Control as an Owner to a Form.But ISN'T possible. The only type could be a Parent for a Form is another Form. However you can do an workaround as is: Get the Controls from Form2 and Replace Controls on Form1 (using those as copy). – G3nt_M3caj Nov 12 '19 at 08:57

1 Answers1

0

You have to craft sepcific forms to allow them to use as controls. Part of our 'child' form declaration and initialization code (for tabbed interface, you know...) (could be not workable as is presented here, but you can get the idea):

Friend Class ControlLikeForm
    Inherits Form

:::::::::

Public Sub New()
    MyBase.New()
    SetStyle(ControlStyles.ResizeRedraw Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True)
    Me.TopLevel = False
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End Sub
Arvo
  • 10,349
  • 1
  • 31
  • 34
  • Hey Thx for all tips. I was able to get this working, when doing it like this: When I open a new TabPage, then the docked UserControl's Tag get's an GUID value. Now I am able to set the Forms.Owner to the MainForm. When changing the Tab, I am able to Hide the form and set the Owner Property to Nothing. When the Tab is opened again, I can search my usercontrols's tag and when I find it, then I Show the form again. Works like a Charme THX a lot – Zero-G. Nov 13 '19 at 12:51
  • @Zero-G. Your question was stated as `I don't know how I can set the owner of the new order form can be set to a control.` - and this (using form inside control) is what I responded and Hans Passant marked as duplicate. Your actual solution (playing with forms visibiilty) certainly solved your main problem - but didn't answer your direct question :) – Arvo Nov 13 '19 at 13:08
  • - Sorry for the late reply. My question's tag is and was: "Set the owner of a Form to a control, not to a form" And so, it has some similarities with the duplicated question, but it is not close to my question. However the solution itself is (what most is a personalized answer) working for me. - But could also help somebody else, because it means, that my answer is a workaround of my direct question. But the duplicated state and the question/answer in the other post is something complete different. – Zero-G. Nov 19 '19 at 08:13