0
我在FlowLayoutPanel
中有許多不同文字的按鈕,我想用特定的字符串找到按鈕。是否可以在不使用循環的情況下找到控件?
目前,我正在做這種方式:
Dim str as String = 'some text
For each btn as Button in FlowLayoutPanel.Controls
If btn.Text = str then
'do something with btn
End If
Next
是否有可能做這樣的事情?
Dim str as String = 'some text
Dim btn as Button = FlowLayoutPanel.Controls.Button.Text with that string
'do something with btn
建議LINQ的很好的答案。如何找到沒有迴路的控制器是OP所提出的問題。當然你的建議並不直接具有'For'循環,但是你的建議仍然是循環而偏離問題。 LINQ方法只是隱藏它;通過直接調用其GetEnumerator方法或使用其中有Controls.OfType的For Each來枚舉該對象。那麼我們如何才能得到沒有循環的控制? – Codexer