用 FlexGrid 网格控件好了。
我给你个例子;
方法,在VB6里,使用菜单,[工程] -- [部件],勾选 Microsoft FlexGrid Control 6.0 (SP6)
该控件图标出现在工具箱里,添加1个到你的窗体上,再添加一个按钮;
界面如下:
编写代码如下:
Option Explicit
Private Sub Command1_Click()
Dim d(5, 5) As Integer
Dim i As Integer
Dim j As Integer
'用随机函数生成二维数组数据
For i = 1 To 5
For j = 1 To 5
d(i, j) = Int(Rnd * 99) + 1
Next j
Next i
'设置网格控件的行列
MSFlexGrid1.Cols = 6
MSFlexGrid1.Rows = 6
'在网格控件里显示二维数组数据
For i = 1 To 5
MSFlexGrid1.Col = i
For j = 1 To 5
MSFlexGrid1.Row = j
MSFlexGrid1.Text = d(i, j)
Next j
Next i
End Sub
运行程序,单击按钮。
我用vs2012 找不到这个- -
哦,我只有VB 2005,但是2012里应该也有 DataGridView 控件吧?
添加1个DataGridView1 控件,一个按钮,代码如下:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim d(5, 5) As Integer
Dim i As Integer
Dim j As Integer
'添加网格每行5列
For i = 1 To 5
DataGridView1.Columns.Add("", "")
Next i
'添加网格为5行----在原来基础上再添加4行
For i = 1 To 4
DataGridView1.Rows.Add()
Next i
'生成5*5的二维数组的数据
For i = 1 To 5
For j = 1 To 5
d(i, j) = Int(Rnd() * 99) + 1
Next
Next
'把数组数据添加到网格里
For i = 1 To 5
For j = 1 To 5
DataGridView1.Rows(i - 1).Cells(j - 1).Value = d(i, j)
Next j
Next i
End Sub
End Class