C# Adding an array of RichTextBoxes to an array of TabPages in a for loop -


picture of c# form

and code:

 using system;     using system.collections.generic;     using system.componentmodel;     using system.data;     using system.drawing;     using system.linq;     using system.text;     using system.threading.tasks;     using system.windows.forms;  namespace inform {     public partial class form1 : form     {         public static tabpage[] tabpages = new tabpage[20];         public static richtextbox[] textboxes = new richtextbox[20];          public form1()         {             initializecomponent();             tabcontrol.tabpages.clear();             (int x = 0; x < 19; x++)             {                 tabpages[x].controls.add(textboxes[x]);    //error here                 //object reference not set instance of object.                 tabcontrol.tabpages.add(tabpages[x]);                 }             }              private void form1_load(object sender, eventargs e)             {              }         }     } 

i trying make basic typing program uses tabcontrol organize each richtextbox in array. when run program returns

object reference not set instance of object.

i have made array of richtextboxes , tabpages can both hold 20 elements(is right word?) problem occurs. function control.add() suppose take control value.

the loop meant go through each tabpage , add correct richtextbox it.

i have gone onto msdn see have have

tabpage1.controls.add(new button()); 

instead of my:

tabpages[x].controls.add(textboxes[x]); 

but not work, have done before without the array, last 1 did capped out @ 6 tabs , wanted make more. tried reading pages on internet nothing seemed work, grateful help.

you have write this

public partial class form1 : form {     public static tabpage[] tabpages = new tabpage[20];     public static richtextbox[] textboxes = new richtextbox[20];     public form1()     {         initializecomponent();          tabcontrol1.tabpages.clear();         (int x = 0; x < 19; x++)         {             tabpages[x] = new tabpage();              tabpages[x].controls.add(textboxes[x]);    //error here             //object reference not set instance of object.             tabcontrol1.tabpages.add(tabpages[x]);         }     }      private void form1_load(object sender, eventargs e)     {      } } 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -