Hey everyone, relatively new to C#, and completely new to the C# forums.

Just have a quick question.... I'm making a web service oriented browser, and am trying to use a service that updates a 5-day forecast.

Anyways... I am wondering why my code below does not work:

groupBoxes = new System.Windows.Forms.GroupBox[5]
                        {
                            groupBox1, groupBox2, groupBox3, groupBox4, groupBox5
                        };

The error I receive is "Error 1 The name 'groupBoxes' does not exist in the current context"

Could anyone enlighten me as to how to initialize a new System.Windows.Forms.GroupBox/PictureBox/Label etc...


Here is my full code if you want to see the context in which it is written in:

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;
using System.Xml.XPath;
using cinemaLocator.prxyWeatherForecast;

namespace cinemaLocator
{
    public partial class Form1 : Form
    {
        WeatherForecasts weatherForecasts;
        WeatherForecastSoapClient weatherForecast;
        WeatherData[] weather;
        Bitmap pic;
        public Form1()
        {
            InitializeComponent();
            groupBoxes = new System.Windows.Forms.GroupBox[5]
                        {
                            groupBox1, groupBox2, groupBox3, groupBox4, groupBox5
                        };
            pictureBoxes = new System.Windows.Forms.PictureBox[5]
                        {
                            pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5
                        };
            lowLabels = new System.Windows.Forms.Label[5]
                        {
                            lowLabel1, lowLabel2, lowLabel3, lowLabel4, lowLabel5
                        };
            highLabels = new System.Windows.Forms.Label[5]
                        {
                            highLabel1, highLabel2, highLabel3, highLabel4, highLabel5
                        };
            lowTemps = new System.Windows.Forms.Label[5]
                        {
                            lowTemp1, lowTemp2, lowTemp3, lowTemp4, lowTemp5
                        };
            highTemps = new System.Windows.Forms.Label[5]
                        {
                            highTemp1, highTemp2, highTemp3, highTemp4, highTemp5
                        };

            weatherForecast = new WeatherForecastSoapClient();
            for (int i = 0; i < 5; i++)
                pictureBoxes[i].SizeMode = PictureBoxSizeMode.StretchImage;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            cinemaLocator.USZip.USzip byZip = new cinemaLocator.USZip.USZip();
            System.Xml.XmlNode rtNode = byZip.GetInfoByZip(textBox2.Text);
            XPathNavigator nav = rtNode.CreateNavigator();
            XPathNodeIterator it = nav.Select("/NewDataSet/Table/City");
            location.Text = it.Current.Value;

            weatherForecasts = weatherForecast.GetWeatherByZipCode(textBox2.Text);
            if (weatherForecasts.Details != null)
            {
                weather = weatherForecasts.Details;
                for (int i = 0; i < 5; i++)
                {
                    groupBoxes[i].Text = weather[i].Day;
                    pic = LoadPicture(weather[i].WeatherImage);
                    pictureBoxes[i].Image = (Image)pic;
                    lowTemps[i].Text = weather[i].MinTemperatureF;
                    highTemps[i].Text = weather[i].MaxTemperatureF;
                }
            }
            else
                MessageBox.Show("No weather information returned!");
        }
        private Bitmap LoadPicture(string url)
        {
            HttpWebRequest wreq;
            HttpWebResponse wresp;
            Stream mystream;
            Bitmap bmp;
            bmp = null;
            mystream = null;
            wresp = null;
            try
            {
                wreq = (HttpWebRequest)WebRequest.Create(url);
                wreq.AllowWriteStreamBuffering = true;
                wresp = (HttpWebResponse)wreq.GetResponse();
                if ((mystream = wresp.GetResponseStream()) != null)
                    bmp = new Bitmap(mystream);
            }
            finally
            {
                if (mystream != null)
                    mystream.Close();
                if (wresp != null)
                    wresp.Close();
            }
            return (bmp);
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


    }
}

Hello, winky.
I don't see definition of groupBoxes in your code. Before using variable, you should define it with some type, like you do this here:

WeatherForecasts weatherForecasts;

For initializing GroupBox you could use example from here: GroupBox Class. Also about other components: System.Windows.Forms Namespace.

You probably meant something like

GroupBox[] Groupboxes ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.