How to add panel into another panel [duplicate]












-2
















This question already has an answer here:




  • What is a NullReferenceException, and how do I fix it?

    31 answers




I want to add one of panel1,2,... into panel0 when I click on button1 .



enter image description here



It's my code



private void button3_Click(object sender, EventArgs e)
{
int i = 0;
int j = 0;


Panel pnl = new Panel[3];

while ( i<2)
{
pnl[i].Parent = panel0; // erorr

pnl[i].BackColor = Color.PeachPuff;

pnl[i].Size = new Size(50, 10);
pnl[i].Location = new Point(j+5,10);
panel0.Controls.Add(pnl[i]);
pnl[i].BringToFront();

i++;
j = j + 13;
}
}


enter image description here



Have a suggestion ?










share|improve this question















marked as duplicate by Liam, slugster c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 12:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Could you let us know what's the error you got?

    – Imantas
    Jan 2 at 12:04






  • 2





    well, your panel hasn't initialized yet, you only call the array constructor, but you should still use pnl[i] = new Panel() before you can access its members. For the rest, you should choose between having it as parent, or assigning it to the controls of panel0, as both do pretty much the same

    – Icepickle
    Jan 2 at 12:06








  • 1





    what technology is this? Winforms, WPF, webforms, Xamarin?

    – Liam
    Jan 2 at 12:07











  • It's windows form

    – jsmlz
    Jan 2 at 12:13
















-2
















This question already has an answer here:




  • What is a NullReferenceException, and how do I fix it?

    31 answers




I want to add one of panel1,2,... into panel0 when I click on button1 .



enter image description here



It's my code



private void button3_Click(object sender, EventArgs e)
{
int i = 0;
int j = 0;


Panel pnl = new Panel[3];

while ( i<2)
{
pnl[i].Parent = panel0; // erorr

pnl[i].BackColor = Color.PeachPuff;

pnl[i].Size = new Size(50, 10);
pnl[i].Location = new Point(j+5,10);
panel0.Controls.Add(pnl[i]);
pnl[i].BringToFront();

i++;
j = j + 13;
}
}


enter image description here



Have a suggestion ?










share|improve this question















marked as duplicate by Liam, slugster c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 12:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Could you let us know what's the error you got?

    – Imantas
    Jan 2 at 12:04






  • 2





    well, your panel hasn't initialized yet, you only call the array constructor, but you should still use pnl[i] = new Panel() before you can access its members. For the rest, you should choose between having it as parent, or assigning it to the controls of panel0, as both do pretty much the same

    – Icepickle
    Jan 2 at 12:06








  • 1





    what technology is this? Winforms, WPF, webforms, Xamarin?

    – Liam
    Jan 2 at 12:07











  • It's windows form

    – jsmlz
    Jan 2 at 12:13














-2












-2








-2









This question already has an answer here:




  • What is a NullReferenceException, and how do I fix it?

    31 answers




I want to add one of panel1,2,... into panel0 when I click on button1 .



enter image description here



It's my code



private void button3_Click(object sender, EventArgs e)
{
int i = 0;
int j = 0;


Panel pnl = new Panel[3];

while ( i<2)
{
pnl[i].Parent = panel0; // erorr

pnl[i].BackColor = Color.PeachPuff;

pnl[i].Size = new Size(50, 10);
pnl[i].Location = new Point(j+5,10);
panel0.Controls.Add(pnl[i]);
pnl[i].BringToFront();

i++;
j = j + 13;
}
}


enter image description here



Have a suggestion ?










share|improve this question

















This question already has an answer here:




  • What is a NullReferenceException, and how do I fix it?

    31 answers




I want to add one of panel1,2,... into panel0 when I click on button1 .



enter image description here



It's my code



private void button3_Click(object sender, EventArgs e)
{
int i = 0;
int j = 0;


Panel pnl = new Panel[3];

while ( i<2)
{
pnl[i].Parent = panel0; // erorr

pnl[i].BackColor = Color.PeachPuff;

pnl[i].Size = new Size(50, 10);
pnl[i].Location = new Point(j+5,10);
panel0.Controls.Add(pnl[i]);
pnl[i].BringToFront();

i++;
j = j + 13;
}
}


enter image description here



Have a suggestion ?





This question already has an answer here:




  • What is a NullReferenceException, and how do I fix it?

    31 answers








c# forms panel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 12:23









slugster

42.3k1282127




42.3k1282127










asked Jan 2 at 12:02









jsmlzjsmlz

32




32




marked as duplicate by Liam, slugster c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 12:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Liam, slugster c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 12:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Could you let us know what's the error you got?

    – Imantas
    Jan 2 at 12:04






  • 2





    well, your panel hasn't initialized yet, you only call the array constructor, but you should still use pnl[i] = new Panel() before you can access its members. For the rest, you should choose between having it as parent, or assigning it to the controls of panel0, as both do pretty much the same

    – Icepickle
    Jan 2 at 12:06








  • 1





    what technology is this? Winforms, WPF, webforms, Xamarin?

    – Liam
    Jan 2 at 12:07











  • It's windows form

    – jsmlz
    Jan 2 at 12:13



















  • Could you let us know what's the error you got?

    – Imantas
    Jan 2 at 12:04






  • 2





    well, your panel hasn't initialized yet, you only call the array constructor, but you should still use pnl[i] = new Panel() before you can access its members. For the rest, you should choose between having it as parent, or assigning it to the controls of panel0, as both do pretty much the same

    – Icepickle
    Jan 2 at 12:06








  • 1





    what technology is this? Winforms, WPF, webforms, Xamarin?

    – Liam
    Jan 2 at 12:07











  • It's windows form

    – jsmlz
    Jan 2 at 12:13

















Could you let us know what's the error you got?

– Imantas
Jan 2 at 12:04





Could you let us know what's the error you got?

– Imantas
Jan 2 at 12:04




2




2





well, your panel hasn't initialized yet, you only call the array constructor, but you should still use pnl[i] = new Panel() before you can access its members. For the rest, you should choose between having it as parent, or assigning it to the controls of panel0, as both do pretty much the same

– Icepickle
Jan 2 at 12:06







well, your panel hasn't initialized yet, you only call the array constructor, but you should still use pnl[i] = new Panel() before you can access its members. For the rest, you should choose between having it as parent, or assigning it to the controls of panel0, as both do pretty much the same

– Icepickle
Jan 2 at 12:06






1




1





what technology is this? Winforms, WPF, webforms, Xamarin?

– Liam
Jan 2 at 12:07





what technology is this? Winforms, WPF, webforms, Xamarin?

– Liam
Jan 2 at 12:07













It's windows form

– jsmlz
Jan 2 at 12:13





It's windows form

– jsmlz
Jan 2 at 12:13












1 Answer
1






active

oldest

votes


















0














change Panel pnl = new Panel[3] to:



var pnl  = new List<Panel>{existingPanel1, existingPanel2, existingPanel3};





share|improve this answer
























  • existingPanel1,2,3 are in your form.

    – CodeMan
    Jan 2 at 12:21











  • thank you , How can I do this if the number of panels is too high?

    – jsmlz
    Jan 2 at 12:30











  • foreach (Control control in Controls) if (control is Panel) // and other conditions to add to pnl list

    – CodeMan
    Jan 2 at 12:37











  • Thanks my Friend

    – jsmlz
    Jan 2 at 12:40


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














change Panel pnl = new Panel[3] to:



var pnl  = new List<Panel>{existingPanel1, existingPanel2, existingPanel3};





share|improve this answer
























  • existingPanel1,2,3 are in your form.

    – CodeMan
    Jan 2 at 12:21











  • thank you , How can I do this if the number of panels is too high?

    – jsmlz
    Jan 2 at 12:30











  • foreach (Control control in Controls) if (control is Panel) // and other conditions to add to pnl list

    – CodeMan
    Jan 2 at 12:37











  • Thanks my Friend

    – jsmlz
    Jan 2 at 12:40
















0














change Panel pnl = new Panel[3] to:



var pnl  = new List<Panel>{existingPanel1, existingPanel2, existingPanel3};





share|improve this answer
























  • existingPanel1,2,3 are in your form.

    – CodeMan
    Jan 2 at 12:21











  • thank you , How can I do this if the number of panels is too high?

    – jsmlz
    Jan 2 at 12:30











  • foreach (Control control in Controls) if (control is Panel) // and other conditions to add to pnl list

    – CodeMan
    Jan 2 at 12:37











  • Thanks my Friend

    – jsmlz
    Jan 2 at 12:40














0












0








0







change Panel pnl = new Panel[3] to:



var pnl  = new List<Panel>{existingPanel1, existingPanel2, existingPanel3};





share|improve this answer













change Panel pnl = new Panel[3] to:



var pnl  = new List<Panel>{existingPanel1, existingPanel2, existingPanel3};






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 12:20









CodeManCodeMan

557311




557311













  • existingPanel1,2,3 are in your form.

    – CodeMan
    Jan 2 at 12:21











  • thank you , How can I do this if the number of panels is too high?

    – jsmlz
    Jan 2 at 12:30











  • foreach (Control control in Controls) if (control is Panel) // and other conditions to add to pnl list

    – CodeMan
    Jan 2 at 12:37











  • Thanks my Friend

    – jsmlz
    Jan 2 at 12:40



















  • existingPanel1,2,3 are in your form.

    – CodeMan
    Jan 2 at 12:21











  • thank you , How can I do this if the number of panels is too high?

    – jsmlz
    Jan 2 at 12:30











  • foreach (Control control in Controls) if (control is Panel) // and other conditions to add to pnl list

    – CodeMan
    Jan 2 at 12:37











  • Thanks my Friend

    – jsmlz
    Jan 2 at 12:40

















existingPanel1,2,3 are in your form.

– CodeMan
Jan 2 at 12:21





existingPanel1,2,3 are in your form.

– CodeMan
Jan 2 at 12:21













thank you , How can I do this if the number of panels is too high?

– jsmlz
Jan 2 at 12:30





thank you , How can I do this if the number of panels is too high?

– jsmlz
Jan 2 at 12:30













foreach (Control control in Controls) if (control is Panel) // and other conditions to add to pnl list

– CodeMan
Jan 2 at 12:37





foreach (Control control in Controls) if (control is Panel) // and other conditions to add to pnl list

– CodeMan
Jan 2 at 12:37













Thanks my Friend

– jsmlz
Jan 2 at 12:40





Thanks my Friend

– jsmlz
Jan 2 at 12:40





Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith