This is auto generated code inside InitializeComponent(), it doesn't work because first, pLeft is added to panel before ControlAdded event is added to panel; second - Panel_ControlAdded uses the name of component, which is set after the component is added.
here is the right code, but it will not auto generate this way:
how do I solve this problem?
I don't want to fight auto generation and I want it run as it does but also probably move some assignments into a different method, not sure what's the best way to do this.
C#:
//
// panel
//
panel.BackColor = Color.FromArgb(196, 0, 0, 0);
panel.Controls.Add(pLeft);
panel.Dock = DockStyle.Bottom;
panel.Location = new Point(0, 390);
panel.Name = "panel";
panel.Size = new Size(400, 210);
panel.TabIndex = 2;
panel.ControlAdded += Panel_ControlAdded;
//
// pLeft
//
pLeft.BackColor = Color.FromArgb(0, 0, 0, 0);
pLeft.Location = new Point(0, 3);
pLeft.Name = "pLeft";
pLeft.Size = new Size(131, 207);
pLeft.TabIndex = 0;
pLeft.TabStop = false;
here is the right code, but it will not auto generate this way:
C#:
//
// pLeft
//
pLeft.BackColor = Color.FromArgb(0, 0, 0, 0);
pLeft.Location = new Point(0, 3);
pLeft.Name = "pLeft";
pLeft.Size = new Size(131, 207);
pLeft.TabIndex = 0;
pLeft.TabStop = false;
//
// panel
//
panel.BackColor = Color.FromArgb(196, 0, 0, 0);
panel.ControlAdded += Panel_ControlAdded;
panel.Controls.Add(pLeft);
panel.Dock = DockStyle.Bottom;
panel.Location = new Point(0, 390);
panel.Name = "panel";
panel.Size = new Size(400, 210);
panel.TabIndex = 2;
how do I solve this problem?
I don't want to fight auto generation and I want it run as it does but also probably move some assignments into a different method, not sure what's the best way to do this.