|
-
Feb 24th, 2004, 08:26 AM
#1
Thread Starter
Banned
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
-
Feb 24th, 2004, 12:52 PM
#2
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()
{
}
}
}
-
Feb 24th, 2004, 12:52 PM
#3
Lively Member
Oddly enough it's because there is no menuItems member of Monopoly.MainClass. You have to define it first...
-
Feb 24th, 2004, 12:58 PM
#4
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?
-
Feb 24th, 2004, 01:00 PM
#5
Addicted Member
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.
-
Feb 25th, 2004, 01:13 PM
#6
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|