Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当progressbar崩溃超过它时,如何避免崩溃';s最大值_C#_Progress Bar - Fatal编程技术网

C# 当progressbar崩溃超过它时,如何避免崩溃';s最大值

C# 当progressbar崩溃超过它时,如何避免崩溃';s最大值,c#,progress-bar,C#,Progress Bar,我有一个关于progressbar的问题 我正在Windows窗体应用程序上制作一个游戏。我有一个进度条,用来显示当前的“电源”。就我而言,它的工作原理如下: 每次玩家1攻击。人工智能反击,获得100点能量。当能量达到400时,一个新的伤害就会出现。一切都很顺利。但当我再次按下攻击按钮时。。将超过最大值400,程序将因错误而关闭 所以我的问题是。如何将最大值设置为progressbar并使其不崩溃?有什么办法吗 提前谢谢我要回答我自己的问题 结果是有效的。但它并没有在编程中赢得美丽的价格 以下是

我有一个关于progressbar的问题

我正在Windows窗体应用程序上制作一个游戏。我有一个进度条,用来显示当前的“电源”。就我而言,它的工作原理如下:

每次玩家1攻击。人工智能反击,获得100点能量。当能量达到400时,一个新的伤害就会出现。一切都很顺利。但当我再次按下攻击按钮时。。将超过最大值400,程序将因错误而关闭

所以我的问题是。如何将最大值设置为progressbar并使其不崩溃?有什么办法吗


提前谢谢

我要回答我自己的问题

结果是有效的。但它并没有在编程中赢得美丽的价格

以下是有关进度条的所有代码:

    public void ProgressBarVegeta()
    {
        ProgressPowerVijand1.Value = (int)(vijand1.opladen());
        ProgressPowerVijand1.Maximum = 400;
        if (ProgressPowerVijand1.Value == 400)
        {
            ProgressBarHide();
        }
        //ProgressPowerVijand1.Value = Math.Min(0, ProgressPowerVijand1.Maximum);
    }

    public void ProgressBarHide()
    {
        ProgressPowerVijand1.Hide();
    }
此代码来自字符类:

class Vijand1
{

    public double opladen()
    {
        opladenVijand1 = opladenVijand1 + 100;

        if( opladenVijand1 == 500)
        {
            opladenVijand1 = 0;
        }
        return opladenVijand1;
    }

有了这段代码,每当进度条崩溃时,它就会重置进度条。因此,使用此代码,它将重置并隐藏progressbar。否则,我会看到绿色条,它每次都会将自身重置为400

bar.Value=Math.Min(someValue,bar.max);请输入一些代码和错误,以便回复。对我来说不太好。我试过别的东西。它没有赢得美容的价格,但它现在起作用了:虽然PDid对我不起作用。那怎么会不起作用呢??当然,您可能需要添加最小值的检查:
bar.value=Math.Max(Math.Min(someValue,bar.Max),bar.Min)-重置为零或隐藏并显示完成消息是另一个问题,最佳解决方案取决于应用程序的其余部分。不要做得太快,否则用户甚至不知道它已经完成了。如果你找到了答案,那么标记你的答案,这样其他人可能会有同样的问题,就会得到答案。