AmazingMrBrock
AmazingMrBrock

Reputation: 197

Windows form designer, NumericUpDown not containing a definition

So I'm getting this error

'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

for two numericupdowns that I'm trying to take a value from. I'm not entirely sure why. Was hoping someone would be able to give me a clue as to whats going on. It's a pretty basic windows form program and I haven't changed too much.

This is 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);
        }

    }
}

my program.cs is all stock

and this is the areas where the errors are in the 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);

Yeah I don't have a clue whats going on here I havent modified anything in the mainform.designer.cs file at all so it seems to me like it should be working.

Upvotes: 0

Views: 556

Answers (1)

crthompson
crthompson

Reputation: 15865

Add DiceNumericValueChanged to your main form.

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

You are calling the method here:

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

But there is no reference to it in "this" ("this" being all the partials of mainform)

If you dont want to do anything when the Dice Numeric Value changes, then you can just delete the reference line from the designer.

Upvotes: 1

Related Questions