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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:01:53+00:00 2026-05-30T07:01:53+00:00

I am trying to add a code behind the add button my code is

  • 0

I am trying to add a code behind the add button my code is this:

class CalculateValues
    {
        private int _num1;
        private int _num2;


        public int Num1
        {
            get
            {
                return _num1;
            }
            set
            {
                _num1 = value;
            }
        }
        public int Num2
        {
            get
            {
                return _num2;
            }
            set
            {
                _num2 = value;
            }
        }
        public virtual int calculate()
        {
            return _num1 + _num2;

        }
    }

Here is the other code that has the button on it:

public partial class Form2 : Form
    {
        public Form2()
        {
            CalculateValues myAdd = new CalculateValues();
            MulitplyValues Add = new MulitplyValues();
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            int total = myadd.Add(int.Parse(textBox1.Text), int.Parse(textBox2.Text));    
            MessageBox.Show(total.ToString());

        }

But everytime it tell me 'myAdd' does not exist in the current context
I am not understanding why it is not working. I have even tried a few different ways.

  • 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-05-30T07:01:54+00:00Added an answer on May 30, 2026 at 7:01 am

    This is a scope issue. You define myAdd inside the constructor Form2(), which means it’ll only be available in that scope: only the constructor can use it, after that it’s gone.

    If you want a variable to persist, move it to the class scope.

    I recommend reading this article

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

Sidebar

Related Questions

I was trying the next code without success HTML <a id=addBookButton href=javascript:showForm('addBookButton','add-book','activateAddBookForm'); class=addA><span>Add Book</span></a>
I am trying to add controls to the page from the code behind in
I am trying to add dynamic HTML elements from the code behind file on
we are trying to add ColumnDefinition to a Grid in WPF dynamically from code
I'm trying to add items to a listbox,combobox, radiolist using reflection. The code I
I have a plot (sample code pasted below) that I am trying to add
I am trying to write simple Visual Studio Add-In for code generation. In my
I'm trying to programmatically add dots to a radar screen. The code runs without
I'm trying to find a way to automate some exception logging code to add
I have been trying to learn how to add testing to existing code --

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.