我想制作一个 Flow Layout Panel 并用一堆按钮填充它。我希望在表单顶部有一个文本框来搜索特定按钮。不知道怎么做。当用户搜索时,所有其他按钮都不可见,只有其.text属性匹配的按钮才会可见。
答案 0 :(得分:1)
假设搜索框正在查找按钮的.Text
属性,该文本框的名称为txtSearch
,该面板名为pnlButtons
:
Private Sub txtSearch_TextChanged(sender As Object, e As EventArgs) Handles txtSearch.TextChanged
pnlButtons.SuspendLayout()
For Each c As Control In pnlButtons.Controls
c.Visible = False
Next
Dim matchingButtons = pnlButtons.Controls.OfType(Of Button).Where(Function(b) b.Text.StartsWith(txtSearch.Text))
For Each b As Button In matchingButtons
b.Visible = True
Next
pnlButtons.ResumeLayout()
End Sub