Mac Man
Mac Man

Reputation: 171

Newly added controls won't paint to Form

So I have a Form that is a scale A4 page that allows users to drag and drop controls on the form for printing.

IE where ever the control is on the form its location is used to print the controls data, eg: File name or image, to that point of an A4 page.

However I have created a number of templates for the form that sets the controls in certain locations and adds in any missing controls. When the templates are selected any extra controls don't show on the form even though I call the Invalidate() method.

Here is my code for the method that adds the controls to the Form:

 private void standardIDToolStripMenuItem_Click(object sender, EventArgs e)
 {

     selectedID = true;
     selectedInvoice = false;
     selectedLetter = false;

     lblName.Visible = true;
     lblDOB.Visible = true;
     lblUID.Visible = true;

     lblName.Location = new Point(200, 100);
     lblDOB.Location = new Point(200, 125);
     lblUID.Location = new Point(200, 150);

     lblName2.Text = lblName.Text;
     lblName2.Location = new Point(60, 750);
     lblName2.Enabled = true;
     lblName2.Visible = true;


     lblDOB2.Text = lblDOB.Text;
     lblDOB2.Location = new Point(60, 775);
     lblDOB2.Enabled = true;
     lblDOB2.Visible = true;

     lblUID2.Text = lblUID.Text;
     lblUID2.Location = new Point(60,800);
     lblUID2.Enabled = true;
     lblUID2.Visible = true;

     hidden1.Location = new Point(300, 100);
     DOBHidden.Location = new Point(300, 125);
     UIDHidden.Location = new Point(300, 150);

     #region ID Background placeholder
     PictureBox backPic = new PictureBox();
     backPic.Location = new Point(24, 48);
     backPic.ForeColor = System.Drawing.Color.PaleGreen;
     backPic.Size = new Size(504, 176);
     backPic.Visible = true;
     backPic.Show();
     backPic.SendToBack();

     this.Invalidate();


     #endregion
 }

Why will the new controls not appear on the form when I have called the Invalidate() method to force it to repaint?

Upvotes: 0

Views: 57

Answers (2)

Paweł Swajdo
Paweł Swajdo

Reputation: 391

Mong Zhu seems to be right and I also suggest you to catch a glimpse of some kind of report designer if you can use some third-part libaries ( I'm not sure if winforms privides something like DevExpress reports for example)

I guess that it will be helpful with stuff you are doing in your project.

Upvotes: 0

Mong Zhu
Mong Zhu

Reputation: 23732

It seems that you don't add them to Controls:

please try this on every control after you have specified location and the rest of the control initialization:

this.Controls.Add(lblName)

Upvotes: 2

Related Questions