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 7815145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:25:28+00:00 2026-06-02T05:25:28+00:00

So I’m making a program and I hit a wall, because I don’t know

  • 0

So I’m making a program and I hit a wall, because I don’t know how to pass a variable from one method to another. To explain the situation, I add the code:

1) I create a toolStripMenuItem^ TestIsvalyti on formload.

    private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e)
         {      
            MenuStrip^ menu = gcnew MenuStrip;
            menu->Location = Point(0,0);
            menu->Size = System::Drawing::Size(this->Width, 25);

            ToolStripMenuItem^ ElDienynas = gcnew ToolStripMenuItem;
            ElDienynas->Text = "El. Dienynas";
            menu->Items->Add(ElDienynas);
            Controls->Add(menu);

            //TESTUI
            ToolStripMenuItem^ TestIsvalyti = gcnew ToolStripMenuItem;
            TestIsvalyti->Text = "ISVALYTI";
            menu->Items->Add(TestIsvalyti);
            TestIsvalyti->Click += gcnew EventHandler(this, &Form2::TestIsvalyti_Click);
            Controls->Add(menu);
            //TESTUI

         }

2) I have an event handler, which creates a TabControl^ ElDienynasTab

    private: System::Void menuGrupe_Click(Object^ sender, EventArgs^ e)
         {

             TabControl^ ElDienynasTab = gcnew TabControl;
             ElDienynasTab->Location = Point(14, 40);
             ElDienynasTab->Size = System::Drawing::Size(768, 500);
             Controls->Add(ElDienynasTab);

             TabPage^ LankomumasPazymiai = gcnew TabPage;
             LankomumasPazymiai->Text = "Lankomumas | Pazymiai";
             ElDienynasTab->Controls->Add(LankomumasPazymiai);

             TabPage^ namuDarbai = gcnew TabPage;
             namuDarbai->Text = "Namu darbai";
             ElDienynasTab->Controls->Add(namuDarbai);       
         }

3) I created another event handler for the TestIsvalyti MenuStripItem, which has to remove the ElDienynasTab from the 2) method, but I hit the wall there because I don’t know how to pass the variable to this event handler.

             void TestIsvalyti_Click(System::Object^  sender, System::EventArgs^  e)
         {
              this->Controls->Remove(ElDienynasTab);
         }

Please explain to me how to do it and/or add a piece of code. Thank you very much.

  • 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-02T05:25:30+00:00Added an answer on June 2, 2026 at 5:25 am

    You have two different functions, menuGrupe_Click and TestIsvalyti_Click. Functions can’t see local variables within other functions, so you need to increase the visibility of the TabControl if you really want to use that specific instance from another method.

    Create a field in your form.

    private: TabControl^ ElDienynasTab;
    

    Store the TabControl in the field instead of a local variable.

    this->ElDienynasTab = gcnew TabControl;
    

    If you drag and drop components onto your form with the designer, you’ll see that this is the pattern that’s followed. In fact, unless there’s some reason you need to dynamically create controls inside your Form_Load and menuGrupe_Click calls, you should be using the designer for all of this and not trying to write it yourself. It will put initialization code into InitializeComponent() and handle the creation of the appropriate fields for you.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

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.