.NET 2.x Разные функции для массива CheckBox-ов - Visual Basic .NET
Формулировка задачи:
Приветствую. Решил спросить совета. Есть нужда: 10 чекбоксов.
Нужно в зависимости от чека вызывать функции.
Матрица возможности
- 1 1 1 2 1 3 1 n 2 1 2 2 2 n
Решение задачи: «.NET 2.x Разные функции для массива CheckBox-ов»
textual
Листинг программы
Public Class Form1 Private ch() As CheckBox Private isLoad As Boolean = False Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load ch = {CheckBox1, CheckBox2, CheckBox3, CheckBox4, CheckBox5, CheckBox6, CheckBox7, CheckBox8} isLoad = True End Sub Public Function chState(ByVal chk() As CheckBox) As String Dim cc(chk.Length - 1) As Char For Each ch As CheckBox In chk If ch.Checked Then cc(CInt(ch.Name.Substring(8)) - 1) = "1"c Else cc(CInt(ch.Name.Substring(8)) - 1) = "0"c End If Next Return String.Join("", cc) End Function Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim ss As String = "f" & chState(ch) Try CallByName(Me, ss, CallType.Method, Nothing) 'или ' GetType(Form1).InvokeMember(ss, System.Reflection.BindingFlags.InvokeMethod, Nothing, Me, Nothing) Catch ex As Exception End Try End Sub Public Sub f01010000() MsgBox("f01010000") End Sub Public Sub f11010000() MsgBox("f11010000") End Sub Public Sub f01010100() MsgBox("f01010100") End Sub End Class