在Windows 7 Pro中运行时,用户控件文本框不会更新 [英] User Control Textboxes not updating when run in Windows 7 Pro
问题描述
我有一个带有几个文本框和进度条的用户控件。
I have a usercontrol with a few textboxes and a progressbar.
该程序会更新文本框和进度条,因为它会计算通过十字转门的人。
The programme updates the textboxes and progressbar as it counts people coming through turnstiles.
它在Windows XP和Windows 7旗舰版下运行良好。
It works fine under Windows XP and Windows 7 Ultimate.
但在Windows 7 Pro下它没有。
However under Windows 7 Pro it does not.
它更新OK当程序计数时。当程序试图将文本框清除回"0"时。一切都出错了。
It updates OK when the programme is counting. When the programme tries to clear the textboxes back to "0" it all goes wrong.
进度条变为0但文本框保持不变。如果我单步执行该程序,则表明textbox.text值实际上已更改 为"0"但是usercontrol中的文本框仍然保留了它的旧值。如果我重启计数
usercontrol不会更新。它似乎已挂起。
The progressbar goes to 0 but the textboxes remain unchanged. If I single step the programme it appears that the textbox.text value actualy changes to "0" but the textbox in the usercontrol still retains it's old value. If I the restart counting the usercontrol does not update. it appears that it has hung.
下面是usercontrol中的代码。我尝试了调用方法来尝试它。它可能看起来不漂亮但它的工作原理(在XP下)
below is the code in the usercontrol. I tried the invoke method just to try it. it may not look pretty but it works(under XP)
表单上有12个这样的用户控件,它们在设计时位于表单上并通过数组进行寻址
There are 12 of these usercontrols on the form and they are on the form at design time and addressed via an array
dim MyStands(12)as usStand
dim MyStands(12) as usStand
mystands(1)= usStand1
mystands(1)=usStand1
mystands(2)= usStand2
mystands(2)=usStand2
等....
清除文本框:
for i as integer = 1 to noofstands'可能少于12
for i as integer = 1 to noofstands ' could be less than 12
mystands(i).clearstandcounts
mystands(i).clearstandcounts
next
Public Class usStand
公共财产MyCapacity As Integer
公共财产MyStartCrowd As Integer
公共财产Myspace作为整数
公共财产MyAmber As Integer
公共财产MyRed As Integer
公共财产MyColour As Integer
公共财产InCount As Integer
公共财产MyName As String
公共财产MyID As Integer
公共活动AmberAlert(ByVal ID As Integer)
公共活动RedAlert(ByVal ID As Integer)
公共事件OverFlowAlert(ByVal ID As Integer)
Public UserSize As Long
'Private WithEvents tmrFlash As Timers.Timer
私有财产LastState As Integer = 0
私人财产AmberAlerted As Boolean
私有财产RedAlerted As Boolean
私有财产OverflowAlerted As Boolean
Public Class usStand
Public Property MyCapacity As Integer
Public Property MyStartCrowd As Integer
Public Property Myspace As Integer
Public Property MyAmber As Integer
Public Property MyRed As Integer
Public Property MyColour As Integer
Public Property InCount As Integer
Public Property MyName As String
Public Property MyID As Integer
Public Event AmberAlert(ByVal ID As Integer)
Public Event RedAlert(ByVal ID As Integer)
Public Event OverFlowAlert(ByVal ID As Integer)
Public UserSize As Long
' Private WithEvents tmrFlash As Timers.Timer
Private Property LastState As Integer = 0
Private Property AmberAlerted As Boolean
Private Property RedAlerted As Boolean
Private Property OverflowAlerted As Boolean
Public Sub SetColour(ByVal cn As Integer)
_MyColour = cn
与我合作
.BackColor = Color.FromArgb(cn)
结束
Public Sub SetColour(ByVal cn As Integer)
_MyColour = cn
With Me
.BackColor = Color.FromArgb(cn)
End With
结束时分
Public Sub SetName(ByVal Nm As String)
_MyName = Nm
Me.Label1.Text = _MyName
End Sub
Public Sub SetName(ByVal Nm As String)
_MyName = Nm
Me.Label1.Text = _MyName
结束时分
Public Sub SetFlowRate(ByVal Value As Double)
End Sub
Public Sub SetFlowRate(ByVal Value As Double)
Me.txtFlowRate.Text =价值
结束时分
Public Sub SetTimeToFull(ByVal值为Double)
"  Debug.Print(" SetTimeToFull:"& MyName&"& value)
Me.txtTimetoFull.Text = value
结束时分
Public Sub SetSpace()
Me.txtFlowRate.Text = Value
End Sub
Public Sub SetTimeToFull(ByVal value As Double)
' Debug.Print("SetTimeToFull: " & MyName & " " & value)
Me.txtTimetoFull.Text = value
End Sub
Public Sub SetSpace()
Dim sp As Integer = _MyCapacity - (_InCount + _MyStartCrowd)
txtSpace.Text = sp
结束时分
Private Sub CalcFlowRate()
Dim sp As Integer = _MyCapacity - (_InCount + _MyStartCrowd)
txtSpace.Text = sp
End Sub
Private Sub CalcFlowRate()
结束时分
Public Sub SetCount(ByVal crowd As Integer)
_InCount =人群
End Sub
Public Sub SetCount(ByVal crowd As Integer)
_InCount = crowd
ProgressBar1.Value = _InCount + _MyStartCrowd
'ProgressBar1.ResetText()
label5.Text = _InCount + _MyStartCrowd
SetSpace()
Dim ls As Integer = CheckAlarm()
ProgressBar1.Value = _InCount + _MyStartCrowd
'ProgressBar1.ResetText()
label5.Text = _InCount + _MyStartCrowd
SetSpace()
Dim ls As Integer = CheckAlarm()
选择案例ls $
案例是= 0
Me.label5.BackColor = Color.LightGreen
Me.BackColor = Color.FromArgb(MyColour)
案例Is = 1
Me.label5.BackColor = Color.Khaki
Select Case ls
Case Is = 0
Me.label5.BackColor = Color.LightGreen
Me.BackColor = Color.FromArgb(MyColour)
Case Is = 1
Me.label5.BackColor = Color.Khaki
Case Is = 2
Me.label5.BackColor = Color.Orange
如果不AmberAlerted然后
                   的RaiseEvent安珀警报(MYID)
                  &NBSP ; AmberAlerted = True
结束如果
Case Is = 3
Me.label5.BackColor = Color.Red
如果不是RedAlerted则为
的RaiseEvent RedAlert(MYID)
                  &NBSP ; RedAlerted = True
结束如果
案例Is = 4
Me.BackColor = Color.Red
如果没有,那么OverflowAlerted
                   的RaiseEvent OverFlowAlert(MYID)
                  &NBSP ; OverflowAlerted = True
结束如果
Case Is = 2
Me.label5.BackColor = Color.Orange
If Not AmberAlerted Then
RaiseEvent AmberAlert(MyID)
AmberAlerted = True
End If
Case Is = 3
Me.label5.BackColor = Color.Red
If Not RedAlerted Then
RaiseEvent RedAlert(MyID)
RedAlerted = True
End If
Case Is = 4
Me.BackColor = Color.Red
If Not OverflowAlerted Then
RaiseEvent OverFlowAlert(MyID)
OverflowAlerted = True
End If
结束选择
End Select
结束时分
Public Sub SetCapacity(ByVal capacity As Integer)
_MyCapacity =容量
Me.ProgressBar1.Maximum =容量
结束时分
Public Sub SetStartCrowd(ByVal sc As Integer)
如果sc> _MyCapacity然后是
MSGBOX(QUOT;您StartCrowd输入的值超过支架" ;, MsgBoxStyle.OkOnly的容量)
            退出Sub¥
结束如果
_MyStartCrowd = sc
ProgressBar1.Value = sc
SetSpace()
结束次
End Sub
Public Sub SetCapacity(ByVal capacity As Integer)
_MyCapacity = capacity
Me.ProgressBar1.Maximum = capacity
End Sub
Public Sub SetStartCrowd(ByVal sc As Integer)
If sc > _MyCapacity Then
MsgBox("The value you entered for StartCrowd exceeds the capacity of the stand", MsgBoxStyle.OkOnly)
Exit Sub
End If
_MyStartCrowd = sc
ProgressBar1.Value = sc
SetSpace()
End Sub
Public Sub ClearStandCounts()
尝试'InCount = MyStartCrowd
_InCount = 0
Me.BackColor = Color.FromArgb(_MyColour)
Public Sub ClearStandCounts()
Try ' InCount = MyStartCrowd
_InCount = 0
Me.BackColor = Color.FromArgb(_MyColour)
_Myspace = _MyCapacity - (_InCount + _MyStartCrowd)
$
调用(新的SetTexts(AddressOf DoSetTexts))
_Myspace = _MyCapacity - (_InCount + _MyStartCrowd)
Invoke(New SetTexts(AddressOf DoSetTexts))
'SetSpace()
C ex ex As Exception
MessageBox.Show(ex.Message)
结束尝试
结束时分
私人功能CheckAlarm()As Integer
Dim a,b,c,d As Boolean
a = _InCount> _MyCapacity * _MyAmber / 100
b = _InCount> _MyCapacity * _MyAmber / 100
c = _InCount> _MyCapacity * _MyRed / 100
d = _InCount> _MyCapacity
Dim ca As Integer = 0
如果a Then ca = 1
如果b则ca = 2
如果c则ca = 3
如果d则ca = 4
'如果是InCount> MyCapacity * myAmber1Alert / 100然后
"    ca = 1
'ElseIf InCount> MyCapacity * myAmber2Alert / 100然后
"    ca = 2
'ElseIf InCount> MyCapacity * myRedAlert / 100然后
"    ca = 3
'ElseIf InCount> MyCapacity然后是
"    ca = 4
'结束如果
返回ca $
结束功能
Public Function GetData()As Integer
Dim i As Integer = 0
' SetSpace()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function CheckAlarm() As Integer
Dim a, b, c, d As Boolean
a = _InCount > _MyCapacity * _MyAmber / 100
b = _InCount > _MyCapacity * _MyAmber / 100
c = _InCount > _MyCapacity * _MyRed / 100
d = _InCount > _MyCapacity
Dim ca As Integer = 0
If a Then ca = 1
If b Then ca = 2
If c Then ca = 3
If d Then ca = 4
'If InCount > MyCapacity * myAmber1Alert / 100 Then
' ca = 1
'ElseIf InCount > MyCapacity * myAmber2Alert / 100 Then
' ca = 2
'ElseIf InCount > MyCapacity * myRedAlert / 100 Then
' ca = 3
'ElseIf InCount > MyCapacity Then
' ca = 4
'End If
Return ca
End Function
Public Function GetData() As Integer
Dim i As Integer = 0
返回i $
结束功能
私人代表子SetTexts()
Return i
End Function
Private Delegate Sub SetTexts()
Private Sub DoSetTexts()
Me.txtFlowRate.Focus()
Me.txtFlowRate.Text =" 0"
Me.txtSpace.Text = _Myspace
Me.txtTimeToFull.Text =" 0"
Me.ProgressBar1.Value = _InCount + _MyStartCrowd
Me.label5.Text = _InCount + _MyStartCrowd
Private Sub DoSetTexts()
Me.txtFlowRate.Focus()
Me.txtFlowRate.Text = "0"
Me.txtSpace.Text = _Myspace
Me.txtTimeToFull.Text = "0"
Me.ProgressBar1.Value = _InCount + _MyStartCrowd
Me.label5.Text = _InCount + _MyStartCrowd
Me.label5.BackColor = Color.LightGreen
Me.label5.BackColor = Color.LightGreen
结束小组$
结束班级
End Sub
End Class
任何帮助都将不胜感激。
Any help would be appreciated.
推荐答案
嘿Jim,
我过去经历过flakey视频,这是因为:
When I've experienced flakey video in the past, it's because:
1)我的代码正在运行,并且表格的绘画和刷新程序无法运行。
1) My code is running and the form's paint and refresh routines are blocked from running.
2)我'已覆盖 在代码中绘制事件。
2) I've overridden paint events in code.
如果您的代码没有经常中断,您可以通过调用它来明确告诉控件在您更改它的值后重新绘制它自己.Refresh方法。
If your code doesn't break very often, you can explicitly tell a control to repaint itself after you've changed it's value by calling the .Refresh method.
例如:
Public Sub SetSpace()
Dim sp As Integer = _MyCapacity - ( _InCount + _MyStartCrowd)
txtSpace.Text = sp.toString()
txtSpace.Refresh()
End Sub
Public Sub SetSpace()
Dim sp As Integer = _MyCapacity - (_InCount + _MyStartCrowd)
txtSpace.Text = sp.toString()
txtSpace.Refresh()
End Sub
如果你要覆盖绘制事件,这可能是另一个问题。
If you are overriding the paint event, this could be another problem.
-james
这篇关于在Windows 7 Pro中运行时,用户控件文本框不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!