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

📄 form1.frm

📁 Vb 画函数图 正弦函数 余弦函数 等源码 网上收集
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   6765
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9390
   LinkTopic       =   "Form1"
   ScaleHeight     =   6765
   ScaleWidth      =   9390
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command6 
      Caption         =   "Command6"
      Height          =   495
      Left            =   8160
      TabIndex        =   6
      Top             =   6120
      Width           =   1215
   End
   Begin VB.CommandButton Command5 
      Caption         =   "Command5"
      Height          =   495
      Left            =   6600
      TabIndex        =   5
      Top             =   6120
      Width           =   1215
   End
   Begin VB.CommandButton Command4 
      Caption         =   "Command4"
      Height          =   495
      Left            =   4920
      TabIndex        =   4
      Top             =   6120
      Width           =   1215
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Command3"
      Height          =   495
      Left            =   3240
      TabIndex        =   3
      Top             =   6120
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Command2"
      Height          =   495
      Left            =   1680
      TabIndex        =   2
      Top             =   6120
      Width           =   1215
   End
   Begin VB.PictureBox Picture1 
      Height          =   5655
      Left            =   120
      ScaleHeight     =   5595
      ScaleWidth      =   8835
      TabIndex        =   1
      Top             =   120
      Width           =   8895
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   240
      TabIndex        =   0
      Top             =   6120
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const Pi = 3.1415926535 '定义圆周率
Dim a As Double
Dim wor
'定义用于在Picture1上的一个位置打印字符函数
Private Function PrintWord(X, Y, Word As String)
With Picture1
.CurrentX = X
.CurrentY = Y
.ForeColor = RGB(0, 0, 255)
End With
Picture1.Print Word
End Function
'定义画点函数
Private Function DrawDot(Px, Py, Color)
Picture1.PSet (Px, Py), Color
End Function
Sub XY() '建立直角坐标系
Picture1.DrawWidth = 1 '设置线条宽度
Picture1.Cls
'设定用户坐标系,坐标原点在Picture1中心
Picture1.Scale (-10, 10)-(10, -10)
Picture1.Line (-10, 0)-(10, 0), RGB(0, 0, 255)
Picture1.Line -(9.5, 0.5), RGB(0, 0, 255)
Picture1.Line (10, 0)-(9.5, -0.5), RGB(0, 0, 255)
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.Print "X"
'画 X 轴
Picture1.Line (0, -10)-(0, 10), RGB(0, 0, 255)
Picture1.Line -(0.5, 9.5), RGB(0, 0, 255)
Picture1.Line (0, 10)-(-0.5, 9.5), RGB(0, 0, 255)
Picture1.Print "Y"
'画 Y 轴
For lin = -9 To 9
Picture1.Line (lin, 0)-(lin, 0.25)
wor = PrintWord(lin - 0.5, -0.5, Str(lin))
Picture1.Line (0, lin)-(-0.25, lin)
If lin <> 0 Then
wor = PrintWord(-0.9, lin, Str(lin))
End If
Next lin
Picture1.DrawWidth = 2
End Sub
Private Sub Command1_Click() '画正弦曲线
'用For循环绘点,使其按正弦规律变化。
'步长小,使曲线比较平滑,还能形成动画效果
For a = -2 * Pi To 2 * Pi Step Pi / 6000
Dot = DrawDot(a, Sin(a) * 5, RGB(0, 255, 0))
Next a
wor = PrintWord(3, -6, "正弦曲线 y=Sinx")
End Sub
Private Sub Command2_Click()
For a = -2 * Pi To 2 * Pi Step Pi / 6000
Dot = DrawDot(a, Cos(a) * 5, RGB(255, 0, 0))
Next a
wor = PrintWord(4, 6, "余弦曲线 y=Cosx")
End Sub
Private Sub Command3_Click()
For a = -3 To 3 Step Pi / 6000
Dot = DrawDot(a, a ^ 2 - 1, RGB(0, 0, 0))
Next a
wor = PrintWord(4, 9, "二次曲线 y=x^2")
End Sub
Private Sub Command4_Click()
For a = -8 To 8 Step Pi / 6000
If a = 0 Then GoTo err0 '除数不能为0
Dot = DrawDot(a, 1 / a, RGB(255, 0, 255))
err0:
Next a
wor = PrintWord(6, 2, "双曲线 y=1/x")
End Sub
Private Sub Command5_Click() '清空屏幕
XY
End Sub

Private Sub Command6_Click()
For a = -0.499 * Pi To 0.499 * Pi Step Pi / 6000
Dot = DrawDot(a, Tan(a) * 5, RGB(0, 125, 128))
Next a
wor = PrintWord(3, -6, "正切曲线 y=Tanx")
End Sub

Private Sub Form_Load()
Me.Caption = "数学函数作图?quot;"
Me.Show
Me.AutoRedraw = True
Picture1.BackColor = vbWhite
Command1.Caption = "正弦曲线"
Command2.Caption = "余弦曲线"
Command3.Caption = "二次曲线"
Command4.Caption = "双曲线"
Command5.Caption = "清空"
Command6.Caption = "正切曲线"
XY
End Sub

Private Sub Form_Resize()
Picture1.Width = Me.Width * 0.94
End Sub


⌨️ 快捷键说明

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