Results 1 to 6 of 6

Thread: Some error(s) I can't spot

  1. #1

    Thread Starter
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180

    Some error(s) I can't spot

    Hi,

    I have this code:

    Code:
    using System;
    using System.Windows.Forms;
    using System.Drawing;
    namespace Monopoly
    {
    class MainMenu: Form
    {
    
     static void Main()
     {
    
      Application.Run(new SpelUI());
     }
    
     public MainMenu()
     {
      this.ClientSize = new System.Drawing.Size(1024,768);
      this.ResizeRedraw = true;
      this.FormBorderStyle = FormBorderStyle.None;
      InitializeComponent();
      string[] ButtonName = new string[6] {"newgame", "load", "mplayer" ,"options" ,"credits" ,"exit"};
      PictureBox[] menuItems = new PictureBox[ButtonName.Length];
    
      //this.Text = "Test";
    
     }
    
     public void InitializeComponent()
     {
      //
      // MainMenu
      //
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(1024, 768);
      this.Name = "MainMenu";
     //this.Load += new System.EventHandler(this.MainMenu_Load);
    
      this.BackgroundImage = Image.FromFile(@"E:\Monopoly V2\Pictures\skyscraper.jpg");
      for (int i = 0;i < 6; i++)
      {
       string temp;
       menuItems[i] = new PictureBox();
       menuItems[i].SizeMode = PictureBoxSizeMode.AutoSize;
       menuItems[i].Left = 370;
       menuItems[i].Width = 200;
       menuItems[i].Height = 40;
       menuItems[i].Top = 400 + 60 * i;
       menuItems[i].BackColor = System.Drawing.Color.Transparent;
       menuItems[i].Click += new EventHandler(MenuItemClick);
       menuItems[i].Tag = ButtonName[i];
       temp = System.Environment.CurrentDirectory + @"\Buttons\" + ButtonName[i] + ".gif";
       //MessageBox.Show(temp);
       menuItems[i].Image = Image.FromFile(temp);
       //menuItems[i].Visible = true;
       Controls.Add(menuItems[i]);
      }
     }
    
    
    
     }
     public void MainMenu_Load()
     {
    
     }
     }
    }
    Everytime I run this code, I get this error:

    'The name menuItems doesn't exist in class or namespace Monopoly.MainMenu'

    Can anyone tell me where I should declare the menuItems array and the string array to get rid of this error?

    Thanks.

    MK

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Code:
    using System;
    using System.Windows.Forms;
    using System.Drawing;
    namespace Monopoly
    {
    class MainMenu: Form
    {
     PictureBox[] menuItems;
    
     static void Main()
     {
    
      Application.Run(new SpelUI());
     }
    
     public MainMenu()
     {
      this.ClientSize = new System.Drawing.Size(1024,768);
      this.ResizeRedraw = true;
      this.FormBorderStyle = FormBorderStyle.None;
      InitializeComponent();
      string[] ButtonName = new string[6] {"newgame", "load", "mplayer" ,"options" ,"credits" ,"exit"};
      menuItems = new PictureBox[ButtonName.Length];
    
      //this.Text = "Test";
    
     }
    
     public void InitializeComponent()
     {
      //
      // MainMenu
      //
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(1024, 768);
      this.Name = "MainMenu";
     //this.Load += new System.EventHandler(this.MainMenu_Load);
    
      this.BackgroundImage = Image.FromFile(@"E:\Monopoly V2\Pictures\skyscraper.jpg");
      for (int i = 0;i < 6; i++)
      {
       string temp;
       menuItems[i] = new PictureBox();
       menuItems[i].SizeMode = PictureBoxSizeMode.AutoSize;
       menuItems[i].Left = 370;
       menuItems[i].Width = 200;
       menuItems[i].Height = 40;
       menuItems[i].Top = 400 + 60 * i;
       menuItems[i].BackColor = System.Drawing.Color.Transparent;
       menuItems[i].Click += new EventHandler(MenuItemClick);
       menuItems[i].Tag = ButtonName[i];
       temp = System.Environment.CurrentDirectory + @"\Buttons\" + ButtonName[i] + ".gif";
       //MessageBox.Show(temp);
       menuItems[i].Image = Image.FromFile(temp);
       //menuItems[i].Visible = true;
       Controls.Add(menuItems[i]);
      }
     }
    
    
    
     }
     public void MainMenu_Load()
     {
    
     }
     }
    }

  3. #3
    Lively Member
    Join Date
    Oct 2003
    Location
    Guildford, UK
    Posts
    91
    Oddly enough it's because there is no menuItems member of Monopoly.MainClass. You have to define it first...

  4. #4
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Originally posted by TheManWhoCan
    Oddly enough it's because there is no menuItems member of Monopoly.MainClass. You have to define it first...
    Or perhaps that it was declared in the constructor but referenced in InitializeComponent?

  5. #5
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    Code:
    string[] ButtonName
    should be called in initializecomponents method as well

    Code:
    using System;
    using System.Windows.Forms;
    using System.Drawing;
    namespace Monopoly
    {
    class MainMenu: Form
    {
    
     PictureBox[] menuItems;
     string[] ButtonName;
     static void Main()
     {
    
      Application.Run(new SpelUI());
     }
    
     public MainMenu()
     {
      this.ClientSize = new System.Drawing.Size(1024,768);
      this.ResizeRedraw = true;
      this.FormBorderStyle = FormBorderStyle.None;
      InitializeComponent();
    
      //this.Text = "Test";
    
     }
    
     public void InitializeComponent()
     {
    
      ButtonName = new string[6] {"newgame", "load", "mplayer" ,"options" ,"credits" ,"exit"};
      menuItems = new PictureBox[ButtonName.Length];
      //
      // MainMenu
      //
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(1024, 768);
      this.Name = "MainMenu";
     //this.Load += new System.EventHandler(this.MainMenu_Load);
    
      this.BackgroundImage = Image.FromFile(@"E:\Monopoly V2\Pictures\skyscraper.jpg");
      for (int i = 0;i < 6; i++)
      {
       string temp;
       menuItems[i] = new PictureBox();
       menuItems[i].SizeMode = PictureBoxSizeMode.AutoSize;
       menuItems[i].Left = 370;
       menuItems[i].Width = 200;
       menuItems[i].Height = 40;
       menuItems[i].Top = 400 + 60 * i;
       menuItems[i].BackColor = System.Drawing.Color.Transparent;
       menuItems[i].Click += new EventHandler(MenuItemClick);
       menuItems[i].Tag = ButtonName[i];
       temp = System.Environment.CurrentDirectory + @"\Buttons\" + ButtonName[i] + ".gif";
       //MessageBox.Show(temp);
       menuItems[i].Image = Image.FromFile(temp);
       //menuItems[i].Visible = true;
       Controls.Add(menuItems[i]);
      }
      }
     }
     public void MainMenu_Load()
     {
    
     }
    }
    Last edited by Tewl; Feb 24th, 2004 at 01:07 PM.

  6. #6
    Lively Member
    Join Date
    Oct 2003
    Location
    Guildford, UK
    Posts
    91
    Yeah well it was late

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width