嘿,所有人,我正在试图弄清楚如何找到这个窗口的标签,当控件名称与程序中的所有其他标签相同时。
WindowsForms10.STATIC.app.0.378734a
WindowsForms10.STATIC.app.0.378734a
WindowsForms10.STATIC.app.0.378734a所有3个标签的名称都相同。我最感兴趣的是进度百分比计数器(1%、2%、3%等)。
在不知道标签的标题的情况下,如何从该标签获取值(当然是使用计时器)?
任何帮助都是最好的!:o)
大卫
发布于 2010-10-15 08:56:59
显而易见的答案是从所有三个标签中获取文本,并检查哪一个看起来像"1%“、"55%”等。
If strText Like "#%" Or strText Like "##%" Or strText = "100%" Then
' ...不太明显的答案(如果Windows API对于您的需求来说太麻烦了)是使用Microsoft UI Automation API。
发布于 2010-10-21 06:07:37
不确定您是否只是在寻找更完整的代码示例,但现在就可以了。
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'This block of code creates a list of all the labels on my form.
'Replace this with code to get a list of labels on the form you are scraping
Dim LblList As New List(Of Label)
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Label Then
LblList.Add(CType(ctrl, Label))
End If
Next
'End
Dim ProgressLblTxt As String = String.Empty
For Each lbl As Label In LblList
If lbl.Text.Contains("%") Then 'You could use several different criteria here as mentioned in the previous answer
ProgressLblTxt = lbl.Text
End If
If ProgressLblTxt <> String.Empty Then Exit For
Next
'Do something with ProgressLblTxt
MsgBox(ProgressLblTxt)
End Subhttps://stackoverflow.com/questions/3903135
复制相似问题