Click here to Skip to main content
15,915,764 members
Home / Discussions / C#
   

C#

 
AnswerRe: help here... square program Pin
Guffa1-May-07 22:27
Guffa1-May-07 22:27 
QuestionC# ASP.NET Printing Puzzle!! Pin
Michael1011-May-07 18:11
Michael1011-May-07 18:11 
AnswerRe: C# ASP.NET Printing Puzzle!! Pin
Christian Graus1-May-07 19:17
protectorChristian Graus1-May-07 19:17 
GeneralRe: C# ASP.NET Printing Puzzle!! Pin
Michael1011-May-07 19:38
Michael1011-May-07 19:38 
QuestionDeserialize an object with XML tags Pin
gsteingr1231-May-07 17:49
gsteingr1231-May-07 17:49 
AnswerRe: Deserialize an object with XML tags Pin
PIEBALDconsult1-May-07 17:55
mvePIEBALDconsult1-May-07 17:55 
AnswerRe: Deserialize an object with XML tags Pin
LongRange.Shooter2-May-07 5:18
LongRange.Shooter2-May-07 5:18 
Questionobject reference not set to an instance of an object Pin
Latheesan1-May-07 16:44
Latheesan1-May-07 16:44 
Hello,

Im trying to workout how to dynamically add tab pages with RichTextBox inside them. So far:

1. I have a form with a input field to enter how many tab pages to create
2. A button that calls the method to create tab page when clicked
3. a tabcontrol with no pages on it

Here is a demo - http://img525.imageshack.us/img525/4519/untitledxv6.jpg[^]

This is the code i have on form1.cs

static int maxTabs = 20;<br />
        TabPage[] tabPages = new TabPage[maxTabs];<br />
        SyntaxHighlightingTextBox[] shtb;<br />
        private void AddTab(int tabNumber)<br />
        {<br />
            for (int i = 0; i < tabNumber; i++)<br />
            {<br />
                // Create a new tab<br />
                tabPages[tabNumber] = new TabPage();<br />
                tabPages[tabNumber].Location = new System.Drawing.Point(4, 22);<br />
                tabPages[tabNumber].Name = "tabPage" + tabNumber.ToString();<br />
                tabPages[tabNumber].Padding = new System.Windows.Forms.Padding(3);<br />
                tabPages[tabNumber].Size = new System.Drawing.Size(403, 386);<br />
                tabPages[tabNumber].TabIndex = tabNumber;<br />
                tabPages[tabNumber].Text = "tabPage " + tabNumber.ToString();<br />
                tabPages[tabNumber].UseVisualStyleBackColor = true;<br />
<br />
                // Create a new RichTextBox inside the tab<br />
                shtb[tabNumber] = new SyntaxHighlightingTextBox();<br />
                shtb[tabNumber].Name = "shtb" + tabNumber.ToString();<br />
                shtb[tabNumber].Location = new Point(0, 0);<br />
                shtb[tabNumber].Dock = DockStyle.Fill;<br />
<br />
                // Add Tab and RichTextBox Control<br />
                tabPages[tabNumber].Controls.Add(shtb[tabNumber]);<br />
                tabControl.Controls.Add(tabPages[tabNumber]);<br />
                <br />
                // Reset of tabControl<br />
                tabPages[tabNumber].SuspendLayout();<br />
                tabPages[tabNumber].ResumeLayout(false);<br />
                int counter = tabControl.Controls.Count;<br />
                tabControl.SelectedIndex = counter - 1;<br />
                this.Text = "TabText1 - " + tabPages[tabNumber].Text;<br />
            }<br />
        }<br />
<br />
        private void AddButton_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                AddTab(int.Parse(tabNumberTextBox.Text));<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                MessageBox.Show("Following Error Occured\r\n\r\n" + ex.Message);<br />
            }<br />
        }


When i build this solution, i get no error at all, but when i enter 1 into the input field and click the add button, i get the following exception error message:

object reference not set to an instance of an object

What does this mean? I've never seen this error before, so i not sure how to fix this. Can someone point me in the right direction on how to fix this error...? It builds correctly, so i assumed i wrote the program correctly.
AnswerRe: object reference not set to an instance of an object Pin
PIEBALDconsult1-May-07 17:08
mvePIEBALDconsult1-May-07 17:08 
GeneralRe: object reference not set to an instance of an object Pin
Latheesan1-May-07 17:23
Latheesan1-May-07 17:23 
GeneralRe: object reference not set to an instance of an object Pin
PIEBALDconsult1-May-07 17:53
mvePIEBALDconsult1-May-07 17:53 
GeneralRe: object reference not set to an instance of an object Pin
Latheesan1-May-07 18:07
Latheesan1-May-07 18:07 
GeneralRe: object reference not set to an instance of an object Pin
PIEBALDconsult1-May-07 18:23
mvePIEBALDconsult1-May-07 18:23 
GeneralRe: object reference not set to an instance of an object Pin
Latheesan1-May-07 18:37
Latheesan1-May-07 18:37 
GeneralRe: object reference not set to an instance of an object Pin
PIEBALDconsult1-May-07 19:08
mvePIEBALDconsult1-May-07 19:08 
GeneralRe: object reference not set to an instance of an object Pin
Christian Graus1-May-07 19:19
protectorChristian Graus1-May-07 19:19 
GeneralRe: object reference not set to an instance of an object Pin
PIEBALDconsult1-May-07 17:57
mvePIEBALDconsult1-May-07 17:57 
GeneralRe: object reference not set to an instance of an object Pin
Latheesan1-May-07 18:02
Latheesan1-May-07 18:02 
GeneralRe: object reference not set to an instance of an object Pin
PIEBALDconsult1-May-07 18:50
mvePIEBALDconsult1-May-07 18:50 
GeneralRe: object reference not set to an instance of an object Pin
Latheesan1-May-07 17:27
Latheesan1-May-07 17:27 
GeneralRe: object reference not set to an instance of an object Pin
Latheesan1-May-07 17:35
Latheesan1-May-07 17:35 
QuestionControl Customization/ New User Controls? Pin
Rocky#1-May-07 15:53
Rocky#1-May-07 15:53 
AnswerRe: Control Customization/ New User Controls? Pin
Christian Graus1-May-07 19:21
protectorChristian Graus1-May-07 19:21 
GeneralRe: Control Customization/ New User Controls? Pin
Rocky#4-May-07 8:56
Rocky#4-May-07 8:56 
Questionworking with VarBinary type field (SQL 2000) in C# 2.0 Pin
Rocky#1-May-07 15:46
Rocky#1-May-07 15:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.