确定将删除文本的控件

时间:2017-04-30 14:11:28

标签: vb.net multidimensional-array drag-and-drop

我在表单上创建了一个标签数组,如下所示::

Private Sub CreateArray()
    ReDim lblArray(mRowCount, mColumnCount)

    Try
        Dim xDistance As Integer
        Dim yDistance As Integer

        xDistance = mFormWidth / mColumnCount
        yDistance = mFormHeight / mRowCount

        Dim iRow As Integer = 0
        Dim iCol As Integer = 0
        Dim RowPosition As Integer
        Dim ColumnPosition As Integer
        For iRow = 0 To mRowCount - 1
            RowPosition = xArray + (xDistance * iRow)
            'Increment through rows
            iCol = 0
            For iCol = 0 To mColumnCount - 1
                lblArray(iRow, iCol) = New Label()
                ColumnPosition = yArray + (mFormHeight - (yDistance * (iCol + 1)))

                'Increment through columns
                With lblArray(iRow, iCol)
                    .AutoSize = False
                    .Location = New Point(RowPosition, ColumnPosition)
                    .Size = New System.Drawing.Size(xDistance, yDistance)
                    .BorderStyle = BorderStyle.FixedSingle
                    .TextAlign = ContentAlignment.MiddleCenter
                    .Text = "(" & iRow & ", " & iCol & ")"
                    If iRow = 0 And iCol = 0 Then
                        .BackColor = hexToRbgNew(mPivotColor)
                    ElseIf iRow = 0 Or iCol = 0 Then
                        .BackColor = hexToRbgNew(mAxisColor)
                        .AllowDrop = False
                    Else
                        .BackColor = hexToRbgNew(mCellColor)
                        .AllowDrop = True
                    End If
                    AddHandler .Click, AddressOf lblArray_Click
                    AddHandler .DragDrop, AddressOf lblArray_DragDrop
                    AddHandler .DragEnter, AddressOf lblArray_DragEnter
                    Me.Controls.Add(lblArray(iRow, iCol))
                End With
            Next
        Next

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try

End Sub

要删除文本以更改指定标签的当前文本,我需要知道我打算采取行动的控件的名称。我认为GetChildAtPoint可以达到目的,但无法确定要作用的特定标签(即当前鼠标位置下的标签)。如何确定具体标签?我想根据我从列表框中提取的信息(唯一的id-> label.tag,以及显示的text-> label.text)更改特定标签的文本和该标签上的标签。网页搜索导致没有具体的方法来确定要对哪个标签采取行动。

可能不是满足需求的最有效方法(可接受建议)。基本尝试是创建一个具有x和y轴的数组,然后使用从值列表框和唯一ID中拖出的值填充矩阵的单元格。

0 个答案:

没有答案
相关问题