Не могу понять почему удаляет несколько строк,вместо одной
Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public int pos = 30;
public int i = 0;
public int tag = 0;
public TextBox[] tex;
public TextBox[] tt;
public TextBox[] tex3;
public CheckBox[] chk;
public Form1()
{
InitializeComponent();
tex = new TextBox[5];
tt = new TextBox[5];
tex3 = new TextBox[5];
chk = new CheckBox[5];
}
public void cikl()
{
for (int g = 0; g < 5; g++)
{
if (tex[g] != null && tex[g].Location.Y == pos)
pos = pos + 30;
else
{
tex[i].Location = new Point(50, pos);
break;
}
}
}
public void Create()
{
tex[i] = new TextBox();
tex[i].Tag = tag.ToString();
cikl();
tex[i].Size = new System.Drawing.Size(120, 20);
Controls.Add(tex[i]);
tt[i] = new TextBox();
tt[i].Tag = tag.ToString();
tt[i].Location = new Point(190, tex[i].Location.Y);
tt[i].Size = new System.Drawing.Size(120, 20);
Controls.Add(tt[i]);
tex3[i] = new TextBox();
tex3[i].Tag = tag.ToString();
tex3[i].Location = new Point(350, tex[i].Location.Y);
tex3[i].Size = new System.Drawing.Size(120, 20);
Controls.Add(tex3[i]);
chk[i] = new CheckBox();
chk[i].Tag = tag.ToString();
chk[i].Text = "";
chk[i].Location = new Point(20, tex[i].Location.Y);
chk[i].Size = new System.Drawing.Size(20, 20);
Controls.Add(chk[i]);
pos = 30;
i++;
tag++;
}
private void button1_Click(object sender, EventArgs e)
{
Create();
}
private void button2_Click(object sender, EventArgs e)
{
foreach (CheckBox w in Controls.OfType<CheckBox>())
{
if (w.Checked == true)
{
foreach (TextBox x in Controls.OfType<TextBox>())
{
if (w.Checked == true && x.Location.Y == w.Location.Y)
{
for (int ff = 0; ff < 5; ff++)
{
if (tex[ff] != null && x.Tag.ToString() == tex[ff].Tag.ToString() && x.Tag.ToString() == tt[ff].Tag.ToString())
{
chk[ff].Dispose();
tex[ff].Dispose();
tt[ff].Dispose();
tex3[ff].Dispose();
chk[ff] = null;
tex[ff] = null;
tt[ff] = null;
tex3[ff] = null;
i--;
for (int kk = 0; kk < 4; kk++)
{
if (tex[kk] == null)
{
tex[kk] = tex[kk + 1];
tt[kk] = tt[kk + 1];
tex3[kk] = tex3[kk + 1];
chk[kk] = chk[kk + 1];
if (tex[kk] != null)
{
chk[kk].Location = new Point(chk[kk + 1].Location.X, chk[kk + 1].Location.Y - 30);
tex[kk].Location = new Point(tex[kk + 1].Location.X, tex[kk + 1].Location.Y - 30);
tt[kk].Location = new Point(tt[kk + 1].Location.X, tt[kk + 1].Location.Y - 30);
tex3[kk].Location = new Point(tex3[kk + 1].Location.X, tex3[kk + 1].Location.Y - 30);
}
chk[kk + 1] = null;
tex[kk + 1] = null;
tt[kk + 1] = null;
tex3[kk + 1] = null;
}
}
}
}
}
}
}
}
pos = 30;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public int pos = 30;
public int i = 0;
public int tag = 0;
public TextBox[] tex;
public TextBox[] tt;
public TextBox[] tex3;
public CheckBox[] chk;
public Form1()
{
InitializeComponent();
tex = new TextBox[5];
tt = new TextBox[5];
tex3 = new TextBox[5];
chk = new CheckBox[5];
}
public void cikl()
{
for (int g = 0; g < 5; g++)
{
if (tex[g] != null && tex[g].Location.Y == pos)
pos = pos + 30;
else
{
tex[i].Location = new Point(50, pos);
break;
}
}
}
public void Create()
{
tex[i] = new TextBox();
tex[i].Tag = tag.ToString();
cikl();
tex[i].Size = new System.Drawing.Size(120, 20);
Controls.Add(tex[i]);
tt[i] = new TextBox();
tt[i].Tag = tag.ToString();
tt[i].Location = new Point(190, tex[i].Location.Y);
tt[i].Size = new System.Drawing.Size(120, 20);
Controls.Add(tt[i]);
tex3[i] = new TextBox();
tex3[i].Tag = tag.ToString();
tex3[i].Location = new Point(350, tex[i].Location.Y);
tex3[i].Size = new System.Drawing.Size(120, 20);
Controls.Add(tex3[i]);
chk[i] = new CheckBox();
chk[i].Tag = tag.ToString();
chk[i].Text = "";
chk[i].Location = new Point(20, tex[i].Location.Y);
chk[i].Size = new System.Drawing.Size(20, 20);
Controls.Add(chk[i]);
pos = 30;
i++;
tag++;
}
private void button1_Click(object sender, EventArgs e)
{
Create();
}
private void button2_Click(object sender, EventArgs e)
{
foreach (CheckBox w in Controls.OfType<CheckBox>())
{
if (w.Checked == true)
{
foreach (TextBox x in Controls.OfType<TextBox>())
{
if (w.Checked == true && x.Location.Y == w.Location.Y)
{
for (int ff = 0; ff < 5; ff++)
{
if (tex[ff] != null && x.Tag.ToString() == tex[ff].Tag.ToString() && x.Tag.ToString() == tt[ff].Tag.ToString())
{
chk[ff].Dispose();
tex[ff].Dispose();
tt[ff].Dispose();
tex3[ff].Dispose();
chk[ff] = null;
tex[ff] = null;
tt[ff] = null;
tex3[ff] = null;
i--;
for (int kk = 0; kk < 4; kk++)
{
if (tex[kk] == null)
{
tex[kk] = tex[kk + 1];
tt[kk] = tt[kk + 1];
tex3[kk] = tex3[kk + 1];
chk[kk] = chk[kk + 1];
if (tex[kk] != null)
{
chk[kk].Location = new Point(chk[kk + 1].Location.X, chk[kk + 1].Location.Y - 30);
tex[kk].Location = new Point(tex[kk + 1].Location.X, tex[kk + 1].Location.Y - 30);
tt[kk].Location = new Point(tt[kk + 1].Location.X, tt[kk + 1].Location.Y - 30);
tex3[kk].Location = new Point(tex3[kk + 1].Location.X, tex3[kk + 1].Location.Y - 30);
}
chk[kk + 1] = null;
tex[kk + 1] = null;
tt[kk + 1] = null;
tex3[kk + 1] = null;
}
}
}
}
}
}
}
}
pos = 30;
}
}
}
Код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public int pos = 30;
public int i = 0;
public int tag = 0;
public TextBox[] tex;
// public TextBox[] tt;
// public TextBox[] tex3;
public CheckBox[] chk;
public Form1()
{
InitializeComponent();
tex = new TextBox[5];
// tt = new TextBox[5];
// tex3 = new TextBox[5];
chk = new CheckBox[5];
}
public void cikl()
{
for (int g = 0; g < 5; g++)
{
if (tex[g] != null && tex[g].Location.Y == pos)
pos = pos + 30;
else
{
tex[i].Location = new Point(50, pos);
break;
}
}
}
public void Create()
{
tex[i] = new TextBox();
tex[i].Tag = tag.ToString();
cikl();
tex[i].Size = new System.Drawing.Size(120, 20);
Controls.Add(tex[i]);
// tt[i] = new TextBox();
// tt[i].Tag = tag.ToString();
// tt[i].Location = new Point(190, tex[i].Location.Y);
// tt[i].Size = new System.Drawing.Size(120, 20);
// Controls.Add(tt[i]);
// tex3[i] = new TextBox();
// tex3[i].Tag = tag.ToString();
// tex3[i].Location = new Point(350, tex[i].Location.Y);
// tex3[i].Size = new System.Drawing.Size(120, 20);
// Controls.Add(tex3[i]);
chk[i] = new CheckBox();
chk[i].Tag = tag.ToString();
chk[i].Text = "";
chk[i].Location = new Point(20, tex[i].Location.Y);
chk[i].Size = new System.Drawing.Size(20, 20);
Controls.Add(chk[i]);
pos = 30;
i++;
tag++;
}
private void button1_Click(object sender, EventArgs e)
{
Create();
}
private void button2_Click(object sender, EventArgs e)
{
foreach (CheckBox w in Controls.OfType<CheckBox>())
{
if (w.Checked == true)
{
foreach (TextBox x in Controls.OfType<TextBox>())
{
if (w.Checked == true && x.Location.Y == w.Location.Y)
{
for (int ff = 0; ff < 5; ff++)
{
if (tex[ff] != null && x.Tag.ToString() == tex[ff].Tag.ToString())// && x.Tag.ToString() == tt[ff].Tag.ToString())
{
chk[ff].Dispose();
tex[ff].Dispose();
// tt[ff].Dispose();
//tex3[ff].Dispose();
chk[ff] = null;
tex[ff] = null;
// tt[ff] = null;
// tex3[ff] = null;
i--;
for (int kk = 0; kk < 4; kk++)
{
if (tex[kk] == null)
{
tex[kk] = tex[kk + 1];
// tt[kk] = tt[kk + 1];
// tex3[kk] = tex3[kk + 1];
chk[kk] = chk[kk + 1];
if (tex[kk] != null)
{
chk[kk].Location = new Point(chk[kk + 1].Location.X, chk[kk + 1].Location.Y - 30);
tex[kk].Location = new Point(tex[kk + 1].Location.X, tex[kk + 1].Location.Y - 30);
// tt[kk].Location = new Point(tt[kk + 1].Location.X, tt[kk + 1].Location.Y - 30);
// tex3[kk].Location = new Point(tex3[kk + 1].Location.X, tex3[kk + 1].Location.Y - 30);
}
chk[kk + 1] = null;
tex[kk + 1] = null;
// tt[kk + 1] = null;
//tex3[kk + 1] = null;
}
}
}
}
}
}
}
}
pos = 30;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public int pos = 30;
public int i = 0;
public int tag = 0;
public TextBox[] tex;
// public TextBox[] tt;
// public TextBox[] tex3;
public CheckBox[] chk;
public Form1()
{
InitializeComponent();
tex = new TextBox[5];
// tt = new TextBox[5];
// tex3 = new TextBox[5];
chk = new CheckBox[5];
}
public void cikl()
{
for (int g = 0; g < 5; g++)
{
if (tex[g] != null && tex[g].Location.Y == pos)
pos = pos + 30;
else
{
tex[i].Location = new Point(50, pos);
break;
}
}
}
public void Create()
{
tex[i] = new TextBox();
tex[i].Tag = tag.ToString();
cikl();
tex[i].Size = new System.Drawing.Size(120, 20);
Controls.Add(tex[i]);
// tt[i] = new TextBox();
// tt[i].Tag = tag.ToString();
// tt[i].Location = new Point(190, tex[i].Location.Y);
// tt[i].Size = new System.Drawing.Size(120, 20);
// Controls.Add(tt[i]);
// tex3[i] = new TextBox();
// tex3[i].Tag = tag.ToString();
// tex3[i].Location = new Point(350, tex[i].Location.Y);
// tex3[i].Size = new System.Drawing.Size(120, 20);
// Controls.Add(tex3[i]);
chk[i] = new CheckBox();
chk[i].Tag = tag.ToString();
chk[i].Text = "";
chk[i].Location = new Point(20, tex[i].Location.Y);
chk[i].Size = new System.Drawing.Size(20, 20);
Controls.Add(chk[i]);
pos = 30;
i++;
tag++;
}
private void button1_Click(object sender, EventArgs e)
{
Create();
}
private void button2_Click(object sender, EventArgs e)
{
foreach (CheckBox w in Controls.OfType<CheckBox>())
{
if (w.Checked == true)
{
foreach (TextBox x in Controls.OfType<TextBox>())
{
if (w.Checked == true && x.Location.Y == w.Location.Y)
{
for (int ff = 0; ff < 5; ff++)
{
if (tex[ff] != null && x.Tag.ToString() == tex[ff].Tag.ToString())// && x.Tag.ToString() == tt[ff].Tag.ToString())
{
chk[ff].Dispose();
tex[ff].Dispose();
// tt[ff].Dispose();
//tex3[ff].Dispose();
chk[ff] = null;
tex[ff] = null;
// tt[ff] = null;
// tex3[ff] = null;
i--;
for (int kk = 0; kk < 4; kk++)
{
if (tex[kk] == null)
{
tex[kk] = tex[kk + 1];
// tt[kk] = tt[kk + 1];
// tex3[kk] = tex3[kk + 1];
chk[kk] = chk[kk + 1];
if (tex[kk] != null)
{
chk[kk].Location = new Point(chk[kk + 1].Location.X, chk[kk + 1].Location.Y - 30);
tex[kk].Location = new Point(tex[kk + 1].Location.X, tex[kk + 1].Location.Y - 30);
// tt[kk].Location = new Point(tt[kk + 1].Location.X, tt[kk + 1].Location.Y - 30);
// tex3[kk].Location = new Point(tex3[kk + 1].Location.X, tex3[kk + 1].Location.Y - 30);
}
chk[kk + 1] = null;
tex[kk + 1] = null;
// tt[kk + 1] = null;
//tex3[kk + 1] = null;
}
}
}
}
}
}
}
}
pos = 30;
}
}
}