vb的程式碼,如何把一張圖分成九張的拼圖,讓他移動。
2006-05-03 05:05:26 · 1 個解答 · 發問者 我在想 1 in 電腦與網際網路 ➔ 程式設計
'置1個PictureBox,Name=Picture1,Index=0Dim W&, H&Private Sub Form_Load()Dim A As Picture, I%, J%, X%, Y&, Z%Show: AutoRedraw = True: ScaleMode = 3W = ScaleWidth: H = ScaleHeightSet A = LoadPicture("C:\Test.bmp") '你的圖片PaintPicture A, 0, 0, W, H, 0, 0, A.Width * 567 \ 1000 \ Screen.TwipsPerPixelX, A.Height * 567 \ 1000 \ Screen.TwipsPerPixelYSet A = NothingW = W / 3: H = H / 3For I = 0 To 2 For J = 0 To 2 If X Then Load Picture1(X) With Picture1(X) .AutoRedraw = True .ScaleMode = 3 .Appearance = 0 .BorderStyle = 1 .DragMode = 1 .Top = J * H .Left = I * W .Height = H .Width = W .Visible = True .PaintPicture Image, 0, 0, .ScaleWidth, .ScaleHeight, .Left, .Top, .ScaleWidth, .ScaleHeight End With X = X + 1 NextNextCls: RandomizeFor Z = 1 To 200 Do I = Int(Rnd * 9) J = Int(Rnd * 9) Loop Until I <> J X = Picture1(I).Left Y = Picture1(I).Top Picture1(I).Left = Picture1(J).Left Picture1(I).Top = Picture1(J).Top Picture1(J).Left = X Picture1(J).Top = YNextEnd SubPrivate Sub Picture1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)Dim A&, B&, I%A = Source.Left: B = Source.TopSource.Left = Picture1(Index).LeftSource.Top = Picture1(Index).TopPicture1(Index).Left = APicture1(Index).Top = BFor A = 0 To 2 For B = 0 To 2 If Picture1(I).Left <> A * W Or Picture1(I).Top <> B * H Then Exit Sub I = I + 1 NextNextMsgBox "恭喜過關"End Sub
2006-05-03 11:55:58 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋