using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3 {
    public partial class Form1 : Form {
        public Form1() {
        void button1_Click(object sender, EventArgs e) {
            MessageBox.Show("Hello!", varying, MessageBoxButtons.OK);

        void textBox1_TextChanged(object sender, EventArgs e) {
            string varying = textBox1.Text;

        void Form1_Load(object sender, EventArgs e) {

So, it kinda works. The MessageBox.Show("Hello!", varying, MessageBoxButton.OK);, if I look into Visual Studio, it says "The name varying doesn't exist in current context", when I try to start program, it tells me there are errors (the one error I already mentioned). But I wanted to run it, in case, well, just to see if it works. It kinda does, form, which I assume to be textBox1. That is kind of an input where you can type in, if I try to type in, the box pops up with as title, that what I type into form itself. Which I kinda good, but the "Hello" thing is missing AND it happens directly after I type anything in it, what I wanted to achieve is that it will prompt content of textBox1 after I click on button1.

Now, it's kinda confusing what I wrote, it's kinda hard to explain this, but you're human and you know what I'm trying to achieve just by looking on the code and the programming part of you, could please help me solve this issue?

Edited by RikTelner

2 Years
Discussion Span
Last Post by deceptikon

The compiler is correct, varying doesn't exist at that point. You declare it in textBox1_TextChanged, but try to use it in a completely different method. Why not just use textBox1.Text directly and not worry about handling TextChanged?

MessageBox.Show("Hello!", textBox1.Text, MessageBoxButtons.OK);

Edited by deceptikon

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.