Good morning, everyone.
I have a question about Forms.
In my application, I can open 2 forms
with grids
where they display information from the factory.
These Grids
are updated every 30 seconds, and are opened with:
StartPosition --> WindowsDefaultLocation.
WindowState --> Normal
Size --> 1002;551
Doubt:
I can initialize them by having form1 open maximized, but in the restore button I can resize the Size
of it to half the monitor screen?
And form2 can identify if there is already an open form and resize Form2 to the second half of the screen with the example below.
Follow the code I'm working on, but incomplete, I'm testing the possibilities so it's not functional, just with a notion.
I thought about using the SizeChanged
event for this application.
int lx, ly;
int sw, sh;
private void frm_Visualizar_Grid_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
lx = this.Location.X;
ly = this.Location.Y;
sh = this.Size.Height;
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
this.Location = Screen.PrimaryScreen.WorkingArea.Location;
}
frm_principal f = new frm_principal();
if (this.WindowState == FormWindowState.Maximized)
{
//string cont = Application.OpenForms.Count.ToString();
string cont = f.MdiChildren.Length.ToString();
if (Convert.ToInt16(cont) < 2)
{
//sw = f.MdiParent.Size.Width;
this.Size = new Size((sw / 2), sh);
this.Location = new Point(lx,ly);
}
else
{
sw = f.MdiParent.Size.Width;
this.Size = new Size((sw / 2), sh);
//if (this.Location.IsEmpty)
f.StartPosition = FormStartPosition.Manual;
}
}
}
Thank you all.
I tried to apply the tip that our friend João Martins mentioned in the answer but did not succeed.
int lx, ly;
int sw, sh;
private void frm_Visualizar_Grid_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Size = Screen.PrimaryScreen.WorkingArea.Size;
this.Location = Screen.PrimaryScreen.WorkingArea.Location;
}
if (this.WindowState == FormWindowState.Maximized)
{
//foreach (frm_Visualizar_Grid frm in MdiChildren)
foreach (Form frm in Application.OpenForms)
{
this.LayoutMdi(System.Windows.Forms.MdiLayout.TileVertical);
}
}
}