Null Ref when adding TabPages at runtimes

Posted by BDotA on Stack Overflow See other posts from Stack Overflow or by BDotA
Published on 2010-05-28T23:06:51Z Indexed on 2010/05/28 23:12 UTC
Read the original article Hit count: 179

Filed under:
|

This is a sample code I wrote to add some tab pages with the controls in them at run time. but when I run it , I get a Null Ref exception error. what part I am doing wrong?

TabPage[] tabPages = new TabPage[2];

CheckBox ck  = new CheckBox();

 

    tabPages[0].BackColor = Color.Firebrick;

    tabPages[0].Controls.Add(ck);

 

    tabPages[1].BackColor = Color.Firebrick;

    tabPages[1].Controls.Add(ck);

 

tabGuy.SuspendLayout();

    tabGuy.TabPages.Add(tabPages[0]);

    tabGuy.TabPages.Add(tabPages[1]);

tabGuy.ResumeLayout();

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms