Windows窗体设计器NumericUpDown不包含定义

本文关键字:包含 定义 NumericUpDown 窗体 Windows | 更新日期: 2023-09-27 18:30:07

所以我得到了这个错误

'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

对于两个数字更新,我正试图从中获取值。我不完全确定为什么。我希望有人能告诉我发生了什么。这是一个非常基本的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);
        }
    }
}

我的程序.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文件中的任何内容,所以在我看来它应该有效。

Windows窗体设计器NumericUpDown不包含定义

DiceNumericValueChanged添加到主表单中。

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

你在这里调用方法:

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

但是在"this"("this"是主形式的所有分部)中没有提到它

如果你不想在骰子数值改变时做任何事情,那么你可以从设计器中删除参考线。