⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 物体弹跳的例子
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   5385
   ClientLeft      =   660
   ClientTop       =   600
   ClientWidth     =   3840
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   5385
   ScaleWidth      =   3840
   Begin VB.Timer tmrMoveImage 
      Interval        =   50
      Left            =   480
      Top             =   840
   End
   Begin VB.PictureBox picHidden 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      Height          =   5325
      Left            =   1800
      Picture         =   "Form1.frx":0000
      ScaleHeight     =   355
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   251
      TabIndex        =   3
      Top             =   2400
      Visible         =   0   'False
      Width           =   3765
   End
   Begin VB.PictureBox picXMask 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      Height          =   1605
      Left            =   2280
      Picture         =   "Form1.frx":8301
      ScaleHeight     =   107
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   91
      TabIndex        =   1
      Top             =   1800
      Visible         =   0   'False
      Width           =   1365
   End
   Begin VB.PictureBox picX 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      Height          =   1605
      Left            =   2640
      Picture         =   "Form1.frx":F69F
      ScaleHeight     =   107
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   91
      TabIndex        =   0
      Top             =   1320
      Visible         =   0   'False
      Width           =   1365
   End
   Begin VB.PictureBox picCanvas 
      AutoRedraw      =   -1  'True
      AutoSize        =   -1  'True
      Height          =   5385
      Left            =   0
      Picture         =   "Form1.frx":16A3D
      ScaleHeight     =   355
      ScaleMode       =   3  'Pixel
      ScaleWidth      =   251
      TabIndex        =   2
      Top             =   0
      Width           =   3825
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Const MERGEPAINT = &HBB0226
Private Const SRCAND = &H8800C6
Private Const SRCCOPY = &HCC0020
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

' Variables for positioning the image.
Dim OldX As Single
Dim OldY As Single
Dim CurX As Single
Dim CurY As Single
Dim PicWid As Single
Dim PicHgt As Single
Dim Xmax As Single
Dim Ymax As Single
Dim Vx As Single
Dim Vy As Single
' Draw the picture at (CurX, CurY).
Private Sub DrawPicture()
    ' Fix the part of the image that was covered.
    BitBlt picCanvas.hDC, _
        OldX, OldY, PicWid, PicHgt, _
        picHidden.hDC, OldX, OldY, SRCCOPY
    OldX = CurX
    OldY = CurY

    ' Paint on the new image.
    BitBlt picCanvas.hDC, _
        CurX, CurY, PicWid, PicHgt, _
        picXMask.hDC, 0, 0, MERGEPAINT
    BitBlt picCanvas.hDC, _
        CurX, CurY, PicWid, PicHgt, _
        picX.hDC, 0, 0, SRCAND

    ' Update the display.
    picCanvas.Refresh
End Sub

' Save picCanvas's original bitmap bytes,
' initialize values, and draw the initial picture.
Private Sub Form_Load()
    ' Make the form fit the picture.
    Width = (Width - ScaleWidth) + picCanvas.Width
    Height = (Height - ScaleHeight) + picCanvas.Height

    PicWid = picX.ScaleWidth
    PicHgt = picX.ScaleHeight
    Xmax = picCanvas.ScaleWidth - PicWid
    Ymax = picCanvas.ScaleHeight - PicHgt
    OldX = 30
    OldY = 30
    CurX = 30
    CurY = 30

    ' Set Vx and Vy to random values
    ' between 10 and 20.
    Randomize
    Vx = 10 + Int(Rnd * 11)
    Vy = 10 + Int(Rnd * 11)
End Sub
Private Sub tmrMoveImage_Timer()
    CurX = CurX + Vx
    CurY = CurY + Vy

    If CurX < 0 Then
        CurX = 0
        Vx = -Vx
    End If
    If CurX > Xmax Then
        CurX = Xmax
        Vx = -Vx
    End If
    If CurY < 0 Then
        CurY = 0
        Vy = -Vy
    End If
    If CurY > Ymax Then
        CurY = Ymax
        Vy = -Vy
    End If
    
    DrawPicture
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -