嗨我需要在按钮点击时打开多个窗口表单(表单相同)。我可以使用以下代码打开它。
private void button1_Click(object sender, EventArgs e)
{
int iPair = int.Parse( textBox1.Text);
int iDeskTopWidth = SystemInformation.VirtualScreen.Width;
int iDeskTopHeight = SystemInformation.VirtualScreen.Height;
int iPreviousFormX = 0;
int iPreviousFormY = 0;
int iRowWidth = 0;
for (int i = 0; i< iPair; i++)
{
var form = new Form1();
Size FormSize = form.Size;
int iWidth = FormSize.Width;
int iHeight = FormSize.Height;
int iNewXLocation = iWidth * i;
form.StartPosition = FormStartPosition.Manual;
int iTotalDesktopWidthNeeded = iPair * iWidth;
if (iNewXLocation + iWidth < iDeskTopWidth)
{
form.DesktopLocation = new Point(iNewXLocation, 0);
}
else if(iRowWidth + iWidth < iDeskTopWidth)
{
form.DesktopLocation = new Point(iPreviousFormX, iDeskTopHeight -(iDeskTopHeight- iHeight));
iPreviousFormX = iPreviousFormX + iWidth;
iPreviousFormY = iPreviousFormY + iHeight;
iRowWidth = iRowWidth + iWidth;
}
else
{
form.DesktopLocation = new Point(iPreviousFormX, iDeskTopHeight - (iDeskTopHeight - iHeight));
iPreviousFormX = iPreviousFormX + iWidth;
iPreviousFormY = iPreviousFormY + iHeight;
}
form.Show();
Point p = new Point(iNewXLocation, 0);
}
}
我想要实现的目标:
1:每次如果用户输入对号(例如:10)并点击输入10对那个表格应该打开。如果桌面端的宽度,那么它应该在那之下打开。
我面临的问题:
1:如果我打开像14这样的大对子,它就超越了桌面。 2:如果我一次打开4对,然后第二次我想再打开4对。它在现有位置打开。但它应该在下面的新位置打开。
任何建议将不胜感激。这是我想要打开表格的图像。enter image description here