0

所以我收到了这个错误

'dicegui.MainForm' does not contain a definition for 'DiceNumericValueChanged' and no extension method 'DiceNumericValueChanged' accepting a first argument of type 'dicegui.MainForm' could be found (are you missing a using directive or an assembly reference?) (CS1061) - C:\Users\b\Documents\Projects\dicegui\dicegui\MainForm.Designer.cs:90,66

对于我试图从中获取值的两个 numericupdowns。我不完全确定为什么。希望有人能给我一个关于发生了什么的线索。这是一个非常基本的 Windows 窗体程序,我并没有改变太多。

这是 mymainform.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace dicegui
{
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
    {

        int maxDice;
        int diceType;
        Random _r =new Random();

        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }

        void RollButtonClick(object sender, EventArgs e)
        {
            maxDice = (int) diceNumeric.Value;
            diceType = (int) sidesNumeric.Value;

            DiceLoop();
        }

        public int RandomDice()
        {
            int n = _r.Next (1, diceType);
            return n;
        }

        public void DiceLoop()
        {
            int result = 0;
            for(int i = 0; i < maxDice; i++)
            {
                result += RandomDice();
            }
            string resultS = Convert.ToString(result);
            //MessageBox.Show("You rolled " + result);
        }

    }
}

我的 program.cs 都是现货

这是 MainForm.Designer.cs 中的错误区域

    this.diceNumeric.Location = new System.Drawing.Point(31, 75);
    this.diceNumeric.Minimum = new decimal(new int[] {
                            1,
                            0,
                            0,
                            0});
    this.diceNumeric.Name = "diceNumeric";
    this.diceNumeric.Size = new System.Drawing.Size(69, 22);
    this.diceNumeric.TabIndex = 3;
    this.diceNumeric.Value = new decimal(new int[] {
                            1,
                            0,
                            0,
                            0});
    this.diceNumeric.ValueChanged += new System.EventHandler(this.DiceNumericValueChanged);
    // 
    // sidesNumeric
    // 
    this.sidesNumeric.Location = new System.Drawing.Point(172, 74);
    this.sidesNumeric.Minimum = new decimal(new int[] {
                            2,
                            0,
                            0,
                            0});
    this.sidesNumeric.Name = "sidesNumeric";
    this.sidesNumeric.Size = new System.Drawing.Size(63, 22);
    this.sidesNumeric.TabIndex = 4;
    this.sidesNumeric.Value = new decimal(new int[] {
                            2,
                            0,
                            0,
                            0});
    this.sidesNumeric.ValueChanged += new System.EventHandler(this.SidesNumericValueChanged);

是的,我不知道这里发生了什么我根本没有修改 mainform.designer.cs 文件中的任何内容,所以在我看来它应该可以工作。

4

1 回答 1

1

添加DiceNumericValueChanged到您的主窗体。

void DiceNumericValueChanged(object sender, EventArgs e)
{
    // some logic about the dice changing
}

您在这里调用该方法:

this.diceNumeric.ValueChanged += new System.EventHandler(this.DiceNumericValueChanged);

但是在“this”中没有提到它(“this”是mainform的所有部分)

如果您不想在 Dice Numeric Value 更改时做任何事情,那么您可以从设计器中删除参考线。

于 2013-09-03T04:33:03.797 回答