winforms 呼叫方法但不运作并产生错误[duplicate]

cqoc49vn  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(97)

此问题在此处已有答案

What does static mean in c#?(4个答案)
27天前关闭。
我们有一个程序,是一个游戏,但我们只是从开始菜单和角色选择开始,我的朋友说。我们是一个4人小组,为这个学校的项目在编程,他说他想要将角色图片框连接到按钮,使得当玩家选择他/她的角色时,该角色将被选为游戏的角色。但我们尝试修复并找到问题的解决方案,但我们无法找到任何可以帮助我们的解决方案。代码中的一切都工作正常,但每当我们调用该方法时,它都会给我们带来问题“Member 'Program.selectform无法使用示例引用访问“(),”用一个类型名来限定它,而不是”我们我们不确定这意味着什么,但我们不能在其他帖子中弄清楚它。任何帮助将非常感谢,因为我们真的希望这个项目是一个成功的,谢谢你。

static void Main(string[] args)
    {
        //Main Menu Window/Form Properties
        Form StartMenuWindow = new Form();
        StartMenuWindow.Text = "Start Menu";
        StartMenuWindow.StartPosition = FormStartPosition.CenterScreen;
        StartMenuWindow.Width = 800;
        StartMenuWindow.Height = 500;
        StartMenuWindow.Text = "Start Menu";
        StartMenuWindow.BackgroundImage = Image.FromFile(@"Essentials\Bg 1.png");
        StartMenuWindow.FormBorderStyle = FormBorderStyle.FixedSingle;

        //Group Two Title Properties (under the game title)
        GroupLab = new Label();
        GroupLab.Font = new Font("Stay Pixel", 15, FontStyle.Bold);
        GroupLab.BackColor = System.Drawing.Color.Transparent;
        GroupLab.ForeColor = Color.Maroon;
        GroupLab.Text = "Made by Group two";
        GroupLab.Size = new Size(196, 34);
        GroupLab.Location = new Point(298, 418);
        GroupLab.Parent = StartMenuWindow;

        //Game Title Properties
        GameTitle = new Label();
        GameTitle.Font = new Font("Stay Pixel", 71, FontStyle.Bold);
        GameTitle.BackColor = System.Drawing.Color.Transparent;
        GameTitle.ForeColor = Color.Maroon;
        GameTitle.Text = "Student Survivors";
        GameTitle.Size = new Size(774, 154);
        GameTitle.Location = new Point(20, 33);
        GameTitle.Parent = StartMenuWindow;

        //Start Button Properties
        Button BtnStart = new Button();
        BtnStart.Font = new Font("Stay Pixel", 36,FontStyle.Bold);
        BtnStart.BackColor = Color.SlateGray;
        BtnStart.Text = "Start";
        BtnStart.Location = new System.Drawing.Point(108, 260);
        BtnStart.Width = 250;
        BtnStart.Height = 100;
        BtnStart.Parent = StartMenuWindow;
        BtnStart.Click += new System.EventHandler(BtnStart_Click);
        
        //Exit Button Properties
        Button BtnExit = new Button();
        BtnExit.Font = new Font("Stay Pixel", 36, FontStyle.Bold);
        BtnExit.BackColor = Color.SlateGray;
        BtnExit.Text = "Exit";
        BtnExit.Location = new System.Drawing.Point(436, 260);
        BtnExit.Width = 250;
        BtnExit.Height = 100;
        BtnExit.Parent = StartMenuWindow;
        BtnExit.Click += new System.EventHandler(BtnExit_Click);
        StartMenuWindow.ShowDialog();
    }

    static void selectform()
    {
        //Form Properties (CHARACTER SELECT WINDOW/FORM)
        Form select = new Form();
        select.Text = "Start Menu";
        select.StartPosition = FormStartPosition.CenterScreen;
        select.Width = 800;
        select.Height = 500;
        select.Text = "Start Menu";
        select.BackgroundImage = Image.FromFile(@"Essentials\Bg 2.png");
        select.FormBorderStyle = FormBorderStyle.FixedSingle;

        //Character Select Title (Choose your Student)
        ChooseTitle = new Label();
        ChooseTitle.Font = new Font("Stay Pixel", 48, FontStyle.Bold);
        ChooseTitle.BackColor = System.Drawing.Color.Transparent;
        ChooseTitle.ForeColor = Color.Maroon;
        ChooseTitle.Text = "Choose your Student";
        ChooseTitle.Width = 589;
        ChooseTitle.Height = 48;
        ChooseTitle.Location = new Point(103, 9);
        ChooseTitle.Parent = select;

        //Character One Properties
        Choosechar1 = new Label();
        Choosechar1.Font = new Font("Stay Pixel", 20, FontStyle.Bold);
        Choosechar1.BackColor = System.Drawing.Color.Transparent;
        Choosechar1.ForeColor = Color.Maroon;
        Choosechar1.Text = "The Normal";
        Choosechar1.Width = 17;
        Choosechar1.Height = 104;
        Choosechar1.Size = new Size(153, 43);
        Choosechar1.Location = new Point(17, 104);
        Choosechar1.Parent = select;

        //Character Two Properties
        Choosechar2 = new Label();
        Choosechar2.Font = new Font("Stay Pixel", 20, FontStyle.Bold);
        Choosechar2.BackColor = System.Drawing.Color.Transparent;
        Choosechar2.ForeColor = Color.Maroon;
        Choosechar2.Text = "The Buff";
        Choosechar2.Size = new Size(115, 43);
        Choosechar2.Location = new Point(244, 104);
        Choosechar2.Parent = select;

        //Character Three Properties
        Choosechar3 = new Label();
        Choosechar3.Font = new Font("Stay Pixel", 20, FontStyle.Bold);
        Choosechar3.BackColor = System.Drawing.Color.Transparent;
        Choosechar3.ForeColor = Color.Maroon;
        Choosechar3.Text = "The Eternal";
        Choosechar3.Size = new Size(154, 43);
        Choosechar3.Location = new Point(416, 104);
        Choosechar3.Parent = select;

        //Character Four Properties
        Choosechar4 = new Label();
        Choosechar4.Font = new Font("Stay Pixel", 20, FontStyle.Bold);
        Choosechar4.BackColor = System.Drawing.Color.Transparent;
        Choosechar4.ForeColor = Color.Maroon;
        Choosechar4.Text = "The Ascendant";
        Choosechar4.Size = new Size(189, 43);
        Choosechar4.Location = new Point(597, 104);
        Choosechar4.Parent = select;

        //CHARACTER PROPERTIES

        //Character One
        Charone = new PictureBox();
        Charone.Image = Image.FromFile("lj.gif");
        Charone.Location = new System.Drawing.Point(20, 150);
        Charone.Size = new System.Drawing.Size(150, 180);
        Charone.SizeMode = PictureBoxSizeMode.Zoom;
        Charone.TabIndex = 0;
        Charone.TabStop = false;
        //Charone.MouseClick += new MouseEventHandler(Charone_Click);
        Charone.Parent = select;

        //Character Two
        Chartwo = new PictureBox();
        Chartwo.Image = Image.FromFile("riane.gif");
        Chartwo.Location = new System.Drawing.Point(220, 150);
        Chartwo.Size = new System.Drawing.Size(150, 180);
        Chartwo.SizeMode = PictureBoxSizeMode.Zoom;
        Chartwo.TabIndex = 1;
        Chartwo.TabStop = false;
        //Chartwo.MouseClick += new MouseEventHandler(Chartwo_Click);
        Chartwo.Parent = select;

        //Chracter Three
        Charthree = new PictureBox();
        Charthree.Image = Image.FromFile("cjay.gif");
        Charthree.Location = new System.Drawing.Point(420, 150);
        Charthree.Size = new System.Drawing.Size(150, 180);
        Charthree.SizeMode = PictureBoxSizeMode.Zoom;
        Charthree.TabIndex = 2;
        Charthree.TabStop = false;
        //Charthree.MouseClick += new MouseEventHandler(Charthree_Click);
        Charthree.Parent = select;

        //Character Four
        Charfour = new PictureBox();
        Charfour.BackColor = System.Drawing.Color.DimGray;
        Charfour.Image = Image.FromFile("jr.gif");
        Charfour.Location = new System.Drawing.Point(615, 150);
        Charfour.Name = "Charfour";
        Charfour.Size = new System.Drawing.Size(150, 180);
        Charfour.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
        Charfour.TabIndex = 3;
        Charfour.TabStop = false;
        //Charfour.Click += new System.EventHandler(Charfour_Click);
        Charfour.Parent = select;

        //START BUTTON PROPERTIES

        Button BtnStartSelect = new Button();
        BtnStartSelect.Font = new Font("Stay Pixel", 36, FontStyle.Bold);
        BtnStartSelect.BackColor = Color.SlateGray;
        BtnStartSelect.Text = "Start";
        BtnStartSelect.Location = new System.Drawing.Point(297, 351);
        BtnStartSelect.Width = 220;
        BtnStartSelect.Height = 77;
        BtnStartSelect.Parent = select;
        select.ShowDialog();
    }


    static void BtnStart_Click(object sender, EventArgs e)
    {
        selectform();
        Program p = new Program();
       p.selectform();
    }
    private static void BtnExit_Click(object sender, System.EventArgs e)
    {
        Application.Exit();
    }

}

}“”

x3naxklr

x3naxklr1#

您的方法被声明为static:

static void selectform()

请将宣告变更为非静态,例如:

void selectform()

或将调用更改为:

Program.selectform();

相关问题