Pass Variable value from one event to another in c#
  • Hello
    I want to pass value of variable from one event to another in c#. Please tell me how can i do this.
    I have an event as follows 


     private void txt_barcode_TextChanged(object sender, EventArgs e)
    {
    string Status="Some Status";
    }


    I want to pass value of Status to the event

     private void button1_Click(object sender, EventArgs e)
    {
    MessageBox.Show(Status);
            }


    Please suggest a better solution
  • 1 Comment sorted by
  • Vote Up0Vote Down WaqasWaqas
    172.00 Karma Accepted Answer
    you can use a global variable see below example.

    string Status = "";
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
                Status = textBox1.Text;
            }

            private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show(Status);
            }


Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Optimum Creative