新建工程,点“工程”->“部件”,在列表中找到并勾选“Microsoft PictureClip Control 6.0”将其添加到工具箱。
在窗体中添加一个PictureClip控件,设置它的Picture属性装载一副图像,设置PictureClip控件的Col属性为3(3列),Row属性为3(3行)。
然后添加一个CommandButton控件Command1,设置其Style为1(图形按钮),再复制8个Command1,提示是否创建控件数组时点“是”,再添加一个CommandButton控件Command2,将Caption属性设为“转换” 如下图:
在窗体中添加以下代码: Option ExplicitPrivate Sub Command2_Click() Dim i As Integer, j As Integer For i = 0 To 8 Command1(i).Caption = "" '去掉文字 Command1(i).Picture = PictureClip1.GraphicCell(i) Command1(i).Width = PictureClip1.CellWidth * 15 Command1(i).Height = PictureClip1.CellHeight * 15 If i Mod 3 = 0 Then j = j + 1 End If If i Mod 3 <> 0 Then Command1(i).Move Command1(i - 1).Left + Command1(i - 1).Width, Command1(0).Top + (j - 1) * Command1(0).Height Else If i <> 0 Then Command1(i).Move Command1(0).Left, Command1(i - 1).Top + Command1(i - 1).Height End If End If Next End Sub
运行: 点击“转换” 实际应用中可能将图片分成的块数不一定,所以按钮可以只创建一个(index设为0),然后通过程序动态创建其它按钮。[此贴子已经被作者于2005-3-11 10:34:42编辑过]
Dim rowPictureBox As Integer, colPictureBox As Integer '将一个图片分成多少行和列
Private Sub Command1_Click() Dim i As Integer, j As Integer, pos As Integer Dim detPicWidth As Single, detPicHeight As Single Dim picWidth As Single, picHeight As Single Dim fileName As String CommonDialog1.ShowOpen fileName = CommonDialog1.fileName picHide.Picture = LoadPicture(fileName) picHide.Refresh picWidth = picHide.Width picHeight = picHide.Height detPicWidth = picWidth / colPictureBox detPicHeight = picHeight / rowPictureBox For i = 0 To rowPictureBox - 1 For j = 0 To colPictureBox - 1 pos = i * rowPictureBox + j Picture1(pos).Width = detPicWidth Picture1(pos).Height = detPicHeight Picture1(pos).PaintPicture picHide, 0, 0, detPicWidth, detPicHeight, j * detPicWidth, i * detPicHeight, detPicWidth, detPicHeight Picture1(pos).Left = picHide.Left + picHide.Width * 1.5 + detPicWidth * j Picture1(pos).Top = picHide.Top + picHide.Height * 0.5 + detPicHeight * i Picture1(pos).Visible = True Next j Next i End Sub
Private Sub Form_Load() '如果要修改那个分割的多少情在这里修改 rowPictureBox = 2 colPictureBox = 2 Picture1(0).Visible = Fals picHide.Left = 10 picHide.Top = Me.Height * 0.3 - picHide.Height For i = 0 To rowPictureBox - 1 For j = 0 To colPictureBox - 1 pos = i * rowPictureBox + j On Error Resume Next Load Picture1(pos) Picture1(pos).Visible = False Next j Next i End Sub
[此贴子已经被作者于2005-3-12 14:50:34编辑过]