所以我收到了这个错误
'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);
}
}
}
我的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文件中的任何内容,所以在我看来它应该可以工作。
答案 0 :(得分: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数值更改时执行任何操作,则可以从设计器中删除参考线。