-1

I use below code to make lightbox effect and it works as i expected. However if i move the parent form it still pop-ups on the center of the screen.

// Execute this code from parent form
Form f = new Form();
f.ShowInTaskbar = false;
f.BackColor = Color.Black;
f.Size = this.Size;
f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
f.StartPosition = this.StartPosition;
f.Opacity = 0.6;
f.Show();

So i changed the above code like below;

f.StartPosition = FormStartPosition.CenterParent;

However it still doesn't pop-up center of the parent form.

Also i tried below, It didn't work too;

f.SetBounds(this.Location.X, this.Location.Y,this.Width, this.Height);

I already tried the solutions here;

Show a child form in the centre of Parent form in C#

They also didn't work.

What i want to do is, creating a second form with the same size and same location.

john true
  • 263
  • 1
  • 5
  • 26
  • @stuard It doesn't duplicated topic. Please remove this mark. I also that topic's answer and they didn't work. Also i already said that in my question. Read my question first. – john true Dec 05 '17 at 11:31
  • I doesn't seem to me that the problem is solved with the existent question, since he defined the "children" form's StartPosition property the same way as the solution points out. – André B Dec 05 '17 at 11:33
  • 1
    check this one out instead https://stackoverflow.com/questions/6463894/creating-form-inside-the-form because i'm inclined to assume that your created form isn't exactly a children of your parent form and that's why you are not achieving your desired behaviour. – André B Dec 05 '17 at 11:36
  • @AndréB you are definitely right. When i change f.show() to f.showdialog();. It worked. – john true Dec 05 '17 at 11:39
  • You never set the parent of f.. as a result your current form is not the parent. – BugFinder Dec 05 '17 at 11:43

1 Answers1

0

Just changing this line;

f.Show();

to this line, It worked;

f.ShowDialog();
john true
  • 263
  • 1
  • 5
  • 26