vb 拼图游戏(图形的分割)的代码
发布网友
发布时间:2022-05-14 00:57
我来回答
共2个回答
热心网友
时间:2023-08-28 06:17
Dim a(0 To 5) As Integer
Private Sub crearnd() '随机分配分割后的图片
Randomize '注意这里放在循环是不同的,可是注意这里有时候图片放不满
For i = 0 To 5
a(i) = Int(Rnd * 6)
If i >= 2 Then
For j = 0 To i - 1
If a(j) = a(i) Then
i = i - 1 '注意这里可以控制i的值,也就是说可以控制For i = 0 To 5里i的值
End If
Next
End If
Next
End Sub
Private Sub Form_Load() '为什么把Picture2(i).Width 改为Picture2(i).scaleWidth不行?
For i = 0 To 5
Picture2(i).Width = Picture1.Width / 3
Picture2(i).Height = Picture1.Height / 2
Next i
End Sub
Private Sub spi_CLICK() 'imagebox没有paintpicture方法
crearnd
Picture2(a(0)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(1)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(2)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 2 * Picture1.ScaleWidth / 3, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(3)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 0, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(4)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(a(5)).PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, 2 * Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 3, Picture1.ScaleHeight / 2
Picture2(0).Move Picture1.Width, 0
Picture2(1).Left = Picture1.Width + Picture2(0).Width: Picture2(1).Top = 0
Picture2(2).Left = Picture1.Width + Picture2(0).Width + Picture2(1).Width: Picture2(2).Top = 0
Picture2(3).Left = Picture1.Width: Picture2(3).Top = Picture2(0).Height
Picture2(4).Left = Picture1.Width + Picture2(3).Width: Picture2(4).Top = Picture2(1).Height
Picture2(5).Left = Picture1.Width + Picture2(3).Width + Picture2(4).Width: Picture2(5).Top = Picture2(2).Height
End Sub
Private Sub Picture2_DragDrop(index As Integer, Source As Control, X As Single, Y As Single) '注意这里用Picture2(index)_DragDrop是错误的,这里可以自动识别index,比如在窗体加一个text,则会显示对象的值
Dim PIC As StdPicture
Set PIC = Source.Image
Set Source.Picture = Picture2(index).Image
Set Picture2(index).Picture = PIC '为什么把picture换为image就不行
End Sub
在窗体上建立一个picture1和一个picture2(index)控件数组,总共包含6个图片框,然后给所有的图片框的autoredraw属性设置为true,就ok了,费了我好的劲,有问题再给我说
热心网友
时间:2023-08-28 06:18
472950999@qq.com 麻烦发给我一下