进度条颜色延迟问题 [英] Progressbar Color Delay Issue

查看:117
本文介绍了进度条颜色延迟问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我的战斗形式设置一个红色进度条。但是,当使用我在某些教程中找到的代码时,使用我发现的触发按钮的延迟就像延迟按下攻击按钮

它的作用是它会降低我的生命值5并降低进度条值5,形成一种健康吧。但当颜色为红色时,会发生以下情况:



生命值= 100

PB.value = 100

点击攻击

生命= 95

PB.Value = 100

点击攻击

Pb .Value = 95

健康= 90



当它是绿色时会发生这种情况:

health = 100

PB.value = 100

点击攻击

生命= 95

PB.Value = 95

点击攻击

Pb.Value = 90

生命值= 90

i想知道什么时候会发生什么PB为绿色,与红色相同,将粘贴我下面的表格代码。

 公开  lblMobH 

声明 Function <> span SendMessage Lib user32 别名 SendMessageA ByVal hwnd 作为 整数 ByVal wMsg 作为 整数 ByVal wParam 作为 整数 ByVal lParam 作为 整数作为 整数
声明自动功能 SendMessage < span class =code-keyword> Lib user32.dll ByVal hWnd As IntPtr ByVal msg As < span class =code-keyword> Integer , ByVal wParam As 整数 ByVal lParam 作为 Integer as Integer
枚举 ProgressBarColor
绿色=& H1
红色=& H2
黄色=& H3
结束 枚举
私有 共享 Sub ChangeProgBarColor( ByVal pbhealth As Windows.Forms.Progre ssBar, ByVal ProgressBar_Color As ProgressBarColor)
SendMessage(pbhealth.Handle,& H410,ProgressBar_Color , 0
结束 Sub

私有 Sub btnAttack_Click( ByVal 发​​件人作为系统。对象 ByVal e As System.EventArgs)句柄 btnAttack.Click
如果 Module1.health> 100 然后
Module1.health = 100
pbHealth.Value = 100
结束 如果
' Module1.health = Module1.health

Label1.Text = PotionUsed
' 攻击暴徒
crit =( 10 * Rnd())* Now.Millisecond / 1000
如果 crit = 6 那么
攻击+ = 25%
结束 如果
如果 Module1.PotionUse d = 0 然后

如果 pbMobHealth.Value> 0 然后
如果攻击< = pbMobHealth.Value 然后
pbMobHealth.Value - = attack
Module1.mhealth - = attack

TextBox .Text = TextBox.Text& vbNewLine& 你被攻击了! - &攻击与 健康&健康与 & pbHealth.Value& & pbMobHealth.Value
attack = 5
Module1.health = Module1.health

否则
pbMobHealth.Value = 0
Module1.mhealth = 0
TextBox.Text = TextBox.Text& vbNewLine& 你被攻击了! - &攻击与 健康&健康与 & pbHealth.Value& & pbMobHealth.Value
attack = 5
Module1.health = Module1.health

结束 如果
ElseIf pbMobHealth.Value<攻击然后
pbMobHealth.Value = 0
Module1.health = Module1.health

结束 如果
lblmhealth.Text = mhealth
' 暴徒攻击你


mcrit =( 10 * Rnd())* Now.Millisecond / 1000

如果 mcrit = 6 那么
mattack + = 25%
结束 如果

如果 pbHealth.Value> 0 然后
如果 mattack < = pbHealth.Value 然后
pbHealth.Value - = mattack
Module1.health - = mattack
TextBox.ForeColor = Color .Red
TextBox.Text = TextBox.Text& vbNewLine& 食人魔被攻击! - &屁股和 健康&健康与 & pbHealth.Value& & pbMobHealth.Value
mattack = 5

其他
pbHealth.Value = 0
Module1.health = 0
TextBox.Text = TextBox.Text& vbNewLine& 食人魔被攻击! - &屁股和 健康&健康与 & pbHealth.Value& & pbMobHealth.Value
mattack = 5

结束 如果
ElseIf pbHealth.Value< mattack 然后
pbHealth.Value = 0
结束 如果
lblhealth.Text = health
结束 如果

如果 PotionUsed = 1 然后
如果 Module1.health> 75 然后
Module1.health = 100
pbHealth.Value = 100
TextBox.Text = TextBox.Text& vbNewLine& 您使用了1个Minor Potion!Health + 15& health
Module1.PotionUsed = 0
Module1.health = Module1.health
pbHealth.Value = Module1.health
其他
pbHealth.Value + = 15
Module1.health + = 15
Module1.PotionUsed = 0
TextBox.Text = TextBox.Text& vbNewLine& 您使用了1个Minor Potion!Health + 15& health
Module1.health = Module1.health

结束 如果
结束 如果
Module1.health = Module1.health

lblhealth.Text = health

pbHealth.Value = lblhealth.Text
End Sub

私有 Sub Form1_Load( ByVal 发​​件人作为系统。对象 ByVal e As System.EventArgs)句柄 MyBase .Load
SendMessage(pbMobHealth.Handle, 1500 2 0

ChangeProgBarColor(pbHealth,ProgressBarColor.Red)
SendMessage(ProgressBar3.Handle, 1040 3 0
结束 Sub

私有 Sub btnpotion_Click( ByVal sender 作为系统。对象 ByVal e As System.EventArgs)句柄 btnPotion.Click
使用 PotionForm 作为 Form2()使用 {。 InvHealth = health} ' 将健康状况传递给Form2。也可以将健康传递给构造函数,我个人经常喜欢。取决于情景......但

PotionForm.ShowDialog()

Dim updatedHealth < span class =code-keyword>作为 整数 = PotionForm.InvHealth ' 检索更新的健康

结束 使用

结束 Sub


私有 Sub btnDefend_Click( ByVal sender As System。 Object ByVal e As System.EventArgs)句柄 btnDefend.Click

如果 pbHealth.Value> 0 然后
pbHealth.Value + = -mattack
health + = -mattack / 2
TextBox.Text = TextBox.Text& vbNewLine& 食人魔被攻击! - & mattack / 2 & 健康
mattack = 5
ElseIf pbHealth.Value< mattack 然后
pbHealth.Value = 0
结束 如果
lblhealth.Text = health
结束 Sub


结束

解决方案

您好,

如果您的进度条没有更新那么你可以使用Application.DoEvents()。此方法

处理当前在消息队列中的所有Windows消息。

阅读此msdn页面

http://msdn.microsoft.com/en-us//library/system.windows.forms.application。 doevents.aspx [ ^ ]



在适当的时候调用此方法。



希望这对您有所帮助。



-

感谢

i need to have a Red progress bar for my battle gui form. but whenichange the colorto red, usingcode i found from some tutorial, there is like a delay on pressing the"attack button"
what it does is it will lowere my Health by 5 and lower the progressbar value by 5, forming a sort of health bar. but when the color is RED this is what happens:

health= 100
PB.value = 100
"Click Attack"
Health = 95
PB.Value = 100
"Click Attack"
Pb.Value = 95
Health = 90

when it is Green this is what happens:
health= 100
PB.value = 100
"Click Attack"
Health = 95
PB.Value = 95
"Click Attack"
Pb.Value = 90
Health = 90
i would like for what happens when the PB is Green, to be the same as when its red, will paste my code for my form below.

Public Class lblMobH

    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Enum ProgressBarColor
        Green = &H1
        Red = &H2
        Yellow = &H3
    End Enum
    Private Shared Sub ChangeProgBarColor(ByVal pbhealth As Windows.Forms.ProgressBar, ByVal ProgressBar_Color As ProgressBarColor)
        SendMessage(pbhealth.Handle, &H410, ProgressBar_Color, 0)
    End Sub
 
    Private Sub btnAttack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAttack.Click
        If Module1.health > 100 Then
            Module1.health = 100
            pbHealth.Value = 100
        End If
        ' Module1.health = Module1.health

        Label1.Text = PotionUsed
        'you attacking mob
        crit = (10 * Rnd()) * Now.Millisecond / 1000
        If crit = 6 Then
            attack += 25%
        End If
        If Module1.PotionUsed = 0 Then

            If pbMobHealth.Value > 0 Then
                If attack <= pbMobHealth.Value Then
                    pbMobHealth.Value -= attack
                    Module1.mhealth -= attack

                    TextBox.Text = TextBox.Text & vbNewLine & "You Attacked! -" & attack & "Health" & health & " " & pbHealth.Value & " " & pbMobHealth.Value
                    attack = 5
                    Module1.health = Module1.health

                Else
                    pbMobHealth.Value = 0
                    Module1.mhealth = 0
                    TextBox.Text = TextBox.Text & vbNewLine & "You Attacked! -" & attack & "Health" & health & " " & pbHealth.Value & " " & pbMobHealth.Value
                    attack = 5
                    Module1.health = Module1.health

                End If
            ElseIf pbMobHealth.Value < attack Then
                pbMobHealth.Value = 0
                Module1.health = Module1.health

            End If
            lblmhealth.Text = mhealth
            'mob attacking you


            mcrit = (10 * Rnd()) * Now.Millisecond / 1000

            If mcrit = 6 Then
                mattack += 25%
            End If

            If pbHealth.Value > 0 Then
                If mattack <= pbHealth.Value Then
                    pbHealth.Value -= mattack
                    Module1.health -= mattack
                    TextBox.ForeColor = Color.Red
                    TextBox.Text = TextBox.Text & vbNewLine & "Ogre Attacked! -" & mattack & "Health " & health & " " & pbHealth.Value & " " & pbMobHealth.Value
                    mattack = 5

                Else
                    pbHealth.Value = 0
                    Module1.health = 0
                    TextBox.Text = TextBox.Text & vbNewLine & "Ogre Attacked! -" & mattack & "Health" & health & " " & pbHealth.Value & " " & pbMobHealth.Value
                    mattack = 5

                End If
            ElseIf pbHealth.Value < mattack Then
                pbHealth.Value = 0
            End If
                lblhealth.Text = health
            End If

        If PotionUsed = 1 Then
            If Module1.health > 75 Then
                Module1.health = 100
                pbHealth.Value = 100
                TextBox.Text = TextBox.Text & vbNewLine & "You used 1 Minor Potion ! Health + 15" & health
                Module1.PotionUsed = 0
                Module1.health = Module1.health
                pbHealth.Value = Module1.health
            Else
                pbHealth.Value += 15
                Module1.health += 15
                Module1.PotionUsed = 0
                TextBox.Text = TextBox.Text & vbNewLine & "You used 1 Minor Potion ! Health + 15" & health
                Module1.health = Module1.health
                
            End If
        End If
        Module1.health = Module1.health

        lblhealth.Text = health

        pbHealth.Value = lblhealth.Text
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SendMessage(pbMobHealth.Handle, 1500, 2, 0)

        ChangeProgBarColor(pbHealth, ProgressBarColor.Red)
        SendMessage(ProgressBar3.Handle, 1040, 3, 0)
    End Sub

    Private Sub btnpotion_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPotion.Click
        Using PotionForm As New Form2() With {.InvHealth = health} 'Pass health to Form2. Could alternatively pass health to constructor, which I personally often prefer. Depends on the scenario though...

            PotionForm.ShowDialog()

            Dim updatedHealth As Integer = PotionForm.InvHealth 'Retrieve updated health

        End Using

    End Sub


    Private Sub btnDefend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDefend.Click

        If pbHealth.Value > 0 Then
            pbHealth.Value += -mattack
            health += -mattack / 2
            TextBox.Text = TextBox.Text & vbNewLine & "Ogre Attacked! -" & mattack / 2 & "Health"
            mattack = 5
        ElseIf pbHealth.Value < mattack Then
            pbHealth.Value = 0
        End If
        lblhealth.Text = health
    End Sub

   
End Class

解决方案

Hi ,
If your progress bar is not updating on time then you can use Application.DoEvents(). This Method
processes all Windows messages currently in the message queue.
Read this msdn page
http://msdn.microsoft.com/en-us//library/system.windows.forms.application.doevents.aspx[^]

Call this method at appropriate time.

Hope this might be helpful to you.

--
Thanks


这篇关于进度条颜色延迟问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆