Child form always in front of parent in Win Forms

Hi,
here an example

test child form

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *


clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
import System.Drawing
import System.Windows.Forms

from System.Drawing import *
from System.Windows.Forms import *

class MainForm(Form):
	def __init__(self):
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._button1 = System.Windows.Forms.Button()
		self._textBox1 = System.Windows.Forms.TextBox()
		self._label1 = System.Windows.Forms.Label()
		self.SuspendLayout()
		# 
		# button1
		# 
		self._button1.Location = System.Drawing.Point(98, 148)
		self._button1.Name = "button1"
		self._button1.Size = System.Drawing.Size(94, 37)
		self._button1.TabIndex = 0
		self._button1.Text = "My Button"
		self._button1.UseVisualStyleBackColor = True
		self._button1.Click += self.Button1Click
		# 
		# textBox1
		# 
		self._textBox1.Location = System.Drawing.Point(61, 102)
		self._textBox1.Name = "textBox1"
		self._textBox1.Size = System.Drawing.Size(167, 20)
		self._textBox1.TabIndex = 1
		# 
		# label1
		# 
		self._label1.Location = System.Drawing.Point(61, 73)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(167, 23)
		self._label1.TabIndex = 2
		self._label1.Text = "Enter a text"
		# 
		# Form1
		# 
		self.ClientSize = System.Drawing.Size(284, 261)
		self.Controls.Add(self._label1)
		self.Controls.Add(self._textBox1)
		self.Controls.Add(self._button1)
		self.Name = "Form1"
		self.Text = "MainForm"
		self.ResumeLayout(False)
		self.PerformLayout()


	def Button1Click(self, sender, e):
		try:
			newMDIChild = ChildForm(self)
			newMDIChild.StartPosition = FormStartPosition.CenterParent
			newMDIChild.ShowDialog(self)
		except Exception as ex:
			print(ex)
			
		
		
class ChildForm(Form):
	def __init__(self, parent):
		self._parent = parent
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._label1 = System.Windows.Forms.Label()
		self.SuspendLayout()
		# 
		# label1
		# 
		self._label1.Location = System.Drawing.Point(47, 41)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(178, 37)
		self._label1.TabIndex = 0
		self._label1.Text = "the enter text is '{}'".format(self._parent._textBox1.Text)
		self._label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		# 
		# Form14
		# 
		self.ClientSize = System.Drawing.Size(284, 128)
		self.Controls.Add(self._label1)
		self.Name = "ChildForm"
		self.Text = "ChildForm"
		self.ResumeLayout(False)
		
MainForm().ShowDialog()
2 Likes