Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:23:56+00:00 2026-06-06T19:23:56+00:00

In Form1.cs i have public const int n = 30; public TabPage[] tp =

  • 0

In Form1.cs i have

public const int n = 30;
public TabPage[] tp = new TabPage[n];

private void toolStripSeparator1_Click(object sender, EventArgs e)
{
    RenameFunc rf = new RenameFunc();
    rf.ShowDialog();
}

In RenameFunc.cs i have

private void button1_Click_1(object sender, EventArgs e)
{
    Form1 frm1 = new Form1();

    if (textBox1.Text != null)
    /*Line 24 */    frm1.tp[Array.IndexOf(frm1.tp, frm1.tabControl1.SelectedTab)].Text = textBox1.Text;
    Application.Exit();

}

tabControl1 is also seted tu Public

in Line 24 i get error

System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.TabControl.get_SelectedTabInternal()
at System.Windows.Forms.TabControl.get_SelectedTab()
at Notepad1._0.RenameFunc.button1_Click_1(Object sender, EventArgs e) in D:\C#\Notepad1.0\Notepad1.0\RenameFunc.cs:line 24

How to correct ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:23:57+00:00Added an answer on June 6, 2026 at 7:23 pm

    I don’t know what tp is, but, I’m sure it’s not initialized and this gives the exception.
    The reason is easily found in the previous line

    Form1 frm1 = new Form1();
    

    here you create a new instance of Form1. You are not referencing the first Form1 from which your RenameFunc has been called.

    Perhaps you could pass a reference to the correct Form1 when you call RenameFunc, for example

    RenameFunc rf = new RenameFunc(this); 
    

    and keep that reference in your RenameFunc internal vars

    public partial class RenameFunc : Form
    {
        private Form1 _caller = null;
        public RenameFunc(Form1 f)
        {
             InitializeComponent();
             _caller = f;       
        }
    

    }

    and in button1_Click_1 use that reference instead of new Form1

       if (textBox1.Text != null)           
            _caller.tp[Array.IndexOf(_caller.tp, _caller.tabControl1.SelectedTab)].Text =
                       textBox1.Text;           
       Application.Exit();       
    

    However a little explanation on tp would be beneficial

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have something like: public partial class Form1 : Form { delegate void
public partial class Form1 : Form { [DllImport(coredll.dll)] static extern int SetWindowLong(IntPtr hWnd, int
I have public site with some forms. Simple question: What kind of informations should
I have a public variable testStr in my applications main form. I have a
I have a Form class partial class ProgressMainForm : Form { public ProgressMainForm() {
I have a form where when it was created it will this query public
I am running a thread in C#. I have web form. I declared public
I have the following Symfony2 form: public function buildForm(FormBuilder $builder, array $options) { $builder
I have a std::vector of some class of the form class A{ public: A():i(someNumber){}
I'm looking at some Java classes that have the following form: public abstract class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.