【问题标题】:How can i describe buttons in matrix?我如何描述矩阵中的按钮?
【发布时间】:2016-01-07 16:38:45
【问题描述】:

我有一个 16*16 矩阵,我试图将它们定义为 vb.net 中的矩阵系列。然后我用这个矩阵做一些视觉展示,比如led展示。


    Dim n As Integer = 16
    Dim l As Integer = 16
    Dim x(n - 1, l - 1) As Integer
    Dim i, j, k As Integer
    For i = 0 To n - 1
        For j = 0 To l - 1
            For k = 1 To 256
                If j= k mod16 then
                buton(k) = x(i, j)
               end if 
            Next

        Next
    Next***

我尝试应用一种算法。但它不起作用。我怎样才能做到这一点?感谢您的关注..

【问题讨论】:

  • 不清楚您遇到了什么问题。您希望代码做什么以及代码实际在做什么?
  • k(mod16)=j 应该是 j= k mod 16 什么是 button(k)?看看这个页面,看看你的问题要包括什么。 minimal reproducible example
  • 感谢您的关注。我的意思是 256 个按钮必须是 x(15,15) 矩阵系列的组成部分。
  • button(k) 当然不起作用。即使我没有由 vb.net 定义
  • 所以你想要代码做的就是将按钮添加到数组 X 中?按钮的名称是什么?它们是从 Button1 开始,到 Button256 结束还是其他什么?

标签: vb.net button matrix


【解决方案1】:

好的,我不久前写过这样的东西 - 我已经根据您的需要对其进行了调整,并且它在我的电脑上运行正常。您需要像这样创建数组 X

Dim x(15,15) As Button

要使用按钮填充数组,请使用此方法..

Private Sub InitializeArray()

    Dim btnslist As New List(Of Button)
    Dim btnNum As Integer
    Dim btnName As String
    Dim splitButtonName() As String
    'add all the buttons to a list
    For Each btnControl As Object In Controls
        Dim btn As Button
        'get button number and add it to the list if it is >0 and <=256
        If TypeOf btnControl Is Button Then
            btn = CType(btnControl, Button)
            'get the button number
            splitButtonName = Split(btn.Name, "n")
            If CInt(splitButtonName(1)) > 0 And CInt(splitButtonName(1)) <= 256 Then
                btnslist.Add(btn)
            End If
        End If
    Next
    'add the buttons to the matrix in the right order
    For i As Integer = 0 To 15
        For j As Integer = 0 To 15
            For k As Integer = 0 To 255
                btnNum = i * 16 + j + 1
                btnName = "Button" & btnNum.ToString
                If btnslist(k).Name = btnName Then
                    x(i, j) = btnslist(k)
                    Exit For
                End If

            Next
        Next
    Next
End Sub

【讨论】:

  • 有一种更短的方法,但我已经有了这段代码
  • 如果答案对您有用,请点击勾选接受。干杯!如果它不让我知道,我会看看它
猜你喜欢
  • 1970-01-01
  • 2023-03-17
  • 2014-04-25
  • 1970-01-01
  • 1970-01-01
  • 2015-07-05
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多