Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a form on current screen in C#?

I want to show a new form in the same window from where it was invoked. I know a way to show this form on PrimaryScreen or Virtual Screen by code similar to as below:

MyForm.Location = Screen.PrimaryScreen.Bounds.Location;

But i want to show it on current screen. Is there a way to find out and show it on current screen?

like image 217
Sam Avatar asked Dec 08 '22 02:12

Sam


1 Answers

I have done something like this to show my form centered to the current screen:

var screen = Screen.FromPoint(Cursor.Position);
myForm.StartPosition = FormStartPosition.Manual;
myForm.Left = screen.Bounds.Left + screen.Bounds.Width / 2 - myForm.Width / 2;
myForm.Top = screen.Bounds.Top + screen.Bounds.Height / 2 - myForm.Height / 2;
like image 63
jreichert Avatar answered Dec 27 '22 20:12

jreichert