C
Carlo Goretti
Guest
Hey!
I need some help..
I have created two panels.. One with dynamic checkboxes and one with other dynamic panels in it..
Im trying to create that if dynamic checkbox.check == true. Then it creates a dynamic panel in the other panel.
The problem comes when the first checkbox and third checkbox are checked. Then it gets a space between them..
I want them after each other..
Im also trying to remove a dynamic panel if i uncheck them but dont get it to work either..
Here is my code:
public void HittaAllaJobb()
{
lstChckBox = new List<CheckBox>();
for (int i = 0; i < test.Count(); i++)
{
box = new CheckBox();
box.Name = i.ToString();
box.Font = new Font(box.Font.FontFamily, 8);
box.AutoSize = true;
box.Text = test.Name;
box.Location = new Point(0, (i * 25));
box.CheckedChanged += new EventHandler(Checkbox_Click);
lstChckBox.Add(box);
CheckboxPanel.Controls.Add(box);
}
}
void Checkbox_Click(object sender, EventArgs e)
{
for (int i = 0; i < lstChckBox.Count(); i++)
{
if (lstChckBox.Checked == true)
{
panel = new Panel();
panel.Name = "VirituellPanel " + i;
panel.AutoSize = true;
panel.Size = new Size(249, 80);
panel.Location = new Point(0, (i * 100));
panel.BorderStyle = BorderStyle.FixedSingle;
SchemalaggareInfoPanel.Controls.Add(panel);
lblRubrik_1 = new Label();
lblRubrik_1.Name = "VirituellLblRubrik1 " + i;
lblRubrik_1.Font = new Font(box.Font.FontFamily, 8);
lblRubrik_1.AutoSize = true;
lblRubrik_1.Text = "Nästa körning är:";
lblRubrik_1.Location = new Point(0, 0);
panel.Controls.Add(lblRubrik_1);
lblRubrik_2 = new Label();
lblRubrik_2.Name = "VirituellLblRubrik2 " + i;
lblRubrik_2.Font = new Font(box.Font.FontFamily, 8);
lblRubrik_2.AutoSize = true;
lblRubrik_2.Text = "Senaste körning:";
lblRubrik_2.Location = new Point(0, 25);
panel.Controls.Add(lblRubrik_2);
lblRubrik_3 = new Label();
lblRubrik_3.Name = "VirituellLblRubrik3 " + i;
lblRubrik_3.Font = new Font(box.Font.FontFamily, 8);
lblRubrik_3.AutoSize = true;
lblRubrik_3.Text = "Status:";
lblRubrik_3.Location = new Point(0, 50);
panel.Controls.Add(lblRubrik_3);
var task = ts.GetTask(test.Name);
string StatusText = "";
lblVärde_1 = new Label();
lblVärde_1.Name = "VirituellLblVärde1 " + i;
lblVärde_1.Font = new Font(box.Font.FontFamily, 8);
lblVärde_1.AutoSize = true;
lblVärde_1.Text = task.NextRunTime.ToString();
lblVärde_1.Location = new Point(lblRubrik_1.Location.X + lblRubrik_1.Size.Width, lblRubrik_1.Location.Y);
panel.Controls.Add(lblVärde_1);
lblVärde_2 = new Label();
lblVärde_2.Name = "VirituellLblVärde2 " + i;
lblVärde_2.Font = new Font(box.Font.FontFamily, 8);
lblVärde_2.AutoSize = true;
lblVärde_2.Text = task.LastRunTime.ToString();
lblVärde_2.Location = new Point(lblRubrik_2.Location.X + lblRubrik_2.Size.Width, lblRubrik_2.Location.Y);
panel.Controls.Add(lblVärde_2);
if (task.IsActive == true)
{
StatusText = "Aktiverad";
}
else
{
StatusText = "Inaktiverad";
}
lblVärde_3 = new Label();
lblVärde_3.Name = "VirituellLblVärde3 " + i;
lblVärde_3.Font = new Font(box.Font.FontFamily, 8);
lblVärde_3.AutoSize = true;
lblVärde_3.Text = StatusText;
lblVärde_3.Location = new Point(lblRubrik_3.Location.X + lblRubrik_3.Size.Width, lblRubrik_3.Location.Y);
panel.Controls.Add(lblVärde_3);
pictureBox = new PictureBox();
pictureBox.Size = new Size(20, 20);
pictureBox.Location = new Point(lblVärde_3.Location.X + lblVärde_3.Size.Width + 5, lblVärde_3.Location.Y - 3);
if (task.IsActive == true)
{
pictureBox.Image = Resources.GreenPicture;
}
else
{
pictureBox.Image = Resources.Gul;
}
panel.Controls.Add(pictureBox);
}
else
{
Control ctrl;
for (int a = Controls.Count - 1; a >= 0; a--)
{
ctrl = Controls[a];
if (ctrl.Name == "VirituellPanel " + i)
{
Controls.RemoveAt(a);
}
}
}
}
}
Ask if you dont understand..
Continue reading...
I need some help..
I have created two panels.. One with dynamic checkboxes and one with other dynamic panels in it..
Im trying to create that if dynamic checkbox.check == true. Then it creates a dynamic panel in the other panel.
The problem comes when the first checkbox and third checkbox are checked. Then it gets a space between them..
I want them after each other..
Im also trying to remove a dynamic panel if i uncheck them but dont get it to work either..
Here is my code:
public void HittaAllaJobb()
{
lstChckBox = new List<CheckBox>();
for (int i = 0; i < test.Count(); i++)
{
box = new CheckBox();
box.Name = i.ToString();
box.Font = new Font(box.Font.FontFamily, 8);
box.AutoSize = true;
box.Text = test.Name;
box.Location = new Point(0, (i * 25));
box.CheckedChanged += new EventHandler(Checkbox_Click);
lstChckBox.Add(box);
CheckboxPanel.Controls.Add(box);
}
}
void Checkbox_Click(object sender, EventArgs e)
{
for (int i = 0; i < lstChckBox.Count(); i++)
{
if (lstChckBox.Checked == true)
{
panel = new Panel();
panel.Name = "VirituellPanel " + i;
panel.AutoSize = true;
panel.Size = new Size(249, 80);
panel.Location = new Point(0, (i * 100));
panel.BorderStyle = BorderStyle.FixedSingle;
SchemalaggareInfoPanel.Controls.Add(panel);
lblRubrik_1 = new Label();
lblRubrik_1.Name = "VirituellLblRubrik1 " + i;
lblRubrik_1.Font = new Font(box.Font.FontFamily, 8);
lblRubrik_1.AutoSize = true;
lblRubrik_1.Text = "Nästa körning är:";
lblRubrik_1.Location = new Point(0, 0);
panel.Controls.Add(lblRubrik_1);
lblRubrik_2 = new Label();
lblRubrik_2.Name = "VirituellLblRubrik2 " + i;
lblRubrik_2.Font = new Font(box.Font.FontFamily, 8);
lblRubrik_2.AutoSize = true;
lblRubrik_2.Text = "Senaste körning:";
lblRubrik_2.Location = new Point(0, 25);
panel.Controls.Add(lblRubrik_2);
lblRubrik_3 = new Label();
lblRubrik_3.Name = "VirituellLblRubrik3 " + i;
lblRubrik_3.Font = new Font(box.Font.FontFamily, 8);
lblRubrik_3.AutoSize = true;
lblRubrik_3.Text = "Status:";
lblRubrik_3.Location = new Point(0, 50);
panel.Controls.Add(lblRubrik_3);
var task = ts.GetTask(test.Name);
string StatusText = "";
lblVärde_1 = new Label();
lblVärde_1.Name = "VirituellLblVärde1 " + i;
lblVärde_1.Font = new Font(box.Font.FontFamily, 8);
lblVärde_1.AutoSize = true;
lblVärde_1.Text = task.NextRunTime.ToString();
lblVärde_1.Location = new Point(lblRubrik_1.Location.X + lblRubrik_1.Size.Width, lblRubrik_1.Location.Y);
panel.Controls.Add(lblVärde_1);
lblVärde_2 = new Label();
lblVärde_2.Name = "VirituellLblVärde2 " + i;
lblVärde_2.Font = new Font(box.Font.FontFamily, 8);
lblVärde_2.AutoSize = true;
lblVärde_2.Text = task.LastRunTime.ToString();
lblVärde_2.Location = new Point(lblRubrik_2.Location.X + lblRubrik_2.Size.Width, lblRubrik_2.Location.Y);
panel.Controls.Add(lblVärde_2);
if (task.IsActive == true)
{
StatusText = "Aktiverad";
}
else
{
StatusText = "Inaktiverad";
}
lblVärde_3 = new Label();
lblVärde_3.Name = "VirituellLblVärde3 " + i;
lblVärde_3.Font = new Font(box.Font.FontFamily, 8);
lblVärde_3.AutoSize = true;
lblVärde_3.Text = StatusText;
lblVärde_3.Location = new Point(lblRubrik_3.Location.X + lblRubrik_3.Size.Width, lblRubrik_3.Location.Y);
panel.Controls.Add(lblVärde_3);
pictureBox = new PictureBox();
pictureBox.Size = new Size(20, 20);
pictureBox.Location = new Point(lblVärde_3.Location.X + lblVärde_3.Size.Width + 5, lblVärde_3.Location.Y - 3);
if (task.IsActive == true)
{
pictureBox.Image = Resources.GreenPicture;
}
else
{
pictureBox.Image = Resources.Gul;
}
panel.Controls.Add(pictureBox);
}
else
{
Control ctrl;
for (int a = Controls.Count - 1; a >= 0; a--)
{
ctrl = Controls[a];
if (ctrl.Name == "VirituellPanel " + i)
{
Controls.RemoveAt(a);
}
}
}
}
}
Ask if you dont understand..
Continue reading...