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

📄 tracer.frm

📁 Visual Basic课程举例1 有很好的例题
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   AutoRedraw      =   -1  'True
   Caption         =   "Tracer"
   ClientHeight    =   6885
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9330
   DrawWidth       =   5
   LinkTopic       =   "Form1"
   ScaleHeight     =   6885
   ScaleWidth      =   9330
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdRePlay 
      BackColor       =   &H00C0E0FF&
      Caption         =   "RePlay"
      Height          =   495
      Left            =   8160
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   120
      Width           =   975
   End
   Begin VB.Label lblTips 
      BackColor       =   &H00FFFFC0&
      Caption         =   "用法:先用鼠标在窗体上随便画,然后点RePlay钮查看回放结果"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Left            =   720
      TabIndex        =   2
      Top             =   240
      Width           =   6720
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "L"
      BeginProperty Font 
         Name            =   "Wingdings"
         Size            =   27.75
         Charset         =   2
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF0000&
      Height          =   615
      Left            =   480
      TabIndex        =   1
      Top             =   1200
      Width           =   465
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Author: c88
' Date: 2008-3-20
'
' 课上讲的问题的实现
' 要求改为动态数组
' 注释来不及加了,应该能看明白吧。
' 有时间我再修改一下
' 学习的好的同学可以想办法实现物体随着曲线拐弯(提示:根据两个点之间连线的斜率决定移动的方向)
' 如果学的再好,可以实现按绘制时的速度进行回放(提示:再用一数组记录绘制时的时间,鼠标按下时开始计时)

Dim TX(1000) As Single, TY(1000) As Single
Dim Dist As Single, PCnt As Integer, RP As Integer, TCnt As Integer


Private Sub cmdRePlay_Click()
    
    RP = 1
    TCnt = PCnt
    Do
        Label1.Left = TX(RP) - Label1.Width / 2
        Label1.Top = TY(RP) - Label1.Height / 2
        RP = RP + 1
        ST = Timer
        Do
            ET = Timer
            DoEvents
        Loop While ET - ST < 0.05
    Loop Until RP > TCnt
    
End Sub

Private Sub Form_Load()
    Dist = 100
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    lblTips.Visible = False
    
    If Button = vbLeftButton Then
        TX(1) = X
        TY(1) = Y
        PCnt = 1
        PSet (X, Y)
    End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = vbLeftButton Then
    If Sqr(Abs(TX(PCnt) - X) ^ 2 + Abs(TY(PCnt) - Y) ^ 2) > Dist Then
        PCnt = PCnt + 1
        TX(PCnt) = X
        TY(PCnt) = Y
        Line -(X, Y)
        Label1.Top = Y - Label1.Height / 2
        Label1.Left = X - Label1.Width / 2
    End If
End If

End Sub

⌨️ 快捷键说明

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