0

我的大脑在这里完全炸了。对不起(毫无疑问)明显的问题,但我看不到树木的树木!

我有一个充当“点池”的变量。numericupdown 控件会影响此点池。如果我增加 numupdown,点池就会减少,反之亦然。我只是无法理解逻辑:(

这是我的“代码”,它的价值......

private void numJobSkill1_ValueChanged(object sender, EventArgs e)
    {

        int difference = (int)(numJobSkill1.Value - numJobSkill1.Minimum);

        /* if (numJobSkill1.Value > numJobSkill1.Minimum)
        {

            POINTPOOL = POINTPOOL - 1;

        } 
        else
        {
            POINTPOOL = POINTPOOL + 1;
        } */

        lblPOINTPOOL.Text = PLAYERPOINTS.ToString();

    }

提前致谢。

4

3 回答 3

1

要确定该值是增加还是减少,您需要记住最后一个值。

// initialize this with the initial value of the UpDownControl
private int _previousValue;

private void numJobSkill1_ValueChanged(object sender, EventArgs e) 
{ 
    int currentValue = numJobSkill1.Value;
    _pointPool -= currentValue - _previousValue;
    _previousValue = currentValue;
} 
于 2012-08-16T08:06:11.907 回答
0

我认为处理这个问题的最简单方法是使 PointPool 成为一个函数,而不是一个变量,其中返回值为 TotalPointsAvailable - TotalPointAllocated,TotalPointsAllocated 是 numJobSkill1 中的值,但它很容易成为几个 updowns 的总和。

private void numJobSkill1_ValueChanged(object sender, EventArgs e)
{
    PLAYERPOINTS = PointPool();
    lblPOINTPOOL.Text = PLAYERPOINTS.ToString();

}

private Int32 TotalPointsAvailable;

private Int32 TotalPointsAllocated()
{
   //Value is a decimal
   return (Int32)numJobSkill1.Value;
}

private Int32 PointPool()
{
    return TotalPointsAvailable-TotalPointsAllocated();
} 
于 2012-08-16T08:14:49.257 回答
-1

尝试这个 :

private void numJobSkill1_ValueChanged(object sender, EventArgs e)
    {

        int difference = (int)(numJobSkill1.Value - numJobSkill1.Minimum);

        if (difference > 0)
        {
            difference--;
        }
        else
        {
            difference++;
        }

        lblPOINTPOOL.Text = difference.ToString();

    }
于 2012-08-16T08:06:43.257 回答