请问有编写二次函数图象的VB代码吗?万分感谢!

 我来答
nekitarc
2007-05-07 · TA获得超过2088个赞
知道小有建树答主
回答量:315
采纳率:0%
帮助的人:544万
展开全部
你把这个Copy到一个txt文件里面,再保存成*.frm
调到工程里面就可以了

VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
BackColor = &H00FFFFFF&
Caption = "Form1"
ClientHeight = 10500
ClientLeft = 165
ClientTop = 735
ClientWidth = 12885
LinkTopic = "Form1"
ScaleHeight = 700
ScaleMode = 3 'Pixel
ScaleWidth = 859
StartUpPosition = 3 '窗口缺省
Begin MSComDlg.CommonDialog Dlg
Left = 5400
Top = 2640
_ExtentX = 847
_ExtentY = 847
_Version = 393216
DialogTitle = "颜色"
End
Begin VB.PictureBox picM
AutoRedraw = -1 'True
BackColor = &H00FFFFFF&
ForeColor = &H00000000&
Height = 10455
Left = 0
ScaleHeight = 18.336
ScaleMode = 7 'Centimeter
ScaleWidth = 22.569
TabIndex = 0
Top = 0
Width = 12855
Begin VB.Shape shpPoint
Height = 135
Left = 1200
Shape = 3 'Circle
Top = 960
Visible = 0 'False
Width = 135
End
End
Begin VB.Menu mnuFile
Caption = "文件"
End
Begin VB.Menu mnuGraph
Caption = "绘图"
Begin VB.Menu mnuAxis
Caption = "构造坐标系"
End
Begin VB.Menu mnuFunction
Caption = "绘制函数"
End
Begin VB.Menu bar1
Caption = "-"
End
Begin VB.Menu mnuColor
Caption = "颜色"
End
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 Type Point
X As Single
Y As Single
End Type

Dim isPointMove As Boolean
Dim MovingPoint As String
Dim O As Point
Dim OPx, OPy As Single
Dim Color As Long

'Private Sub Form_Resize()
' picM.Move 0, 0, Width, Height
'End Sub

Private Sub mnuAxis_Click()
MovePoint
MovingPoint = "O"
End Sub

Private Sub MovePoint()
shpPoint.Visible = True
isPointMove = True
End Sub

Private Sub mnuColor_Click()
Dlg.ShowColor
Color = Dlg.Color
End Sub

Private Sub mnuFunction_Click()
Dim I As Single
For I = -O.X To picM.Width - O.X Step 0.1
DrawP I, Func(I)
Next I
OPx = 0
OPy = 0
End Sub

Private Sub DrawP(ByVal Px, Py As Single)
Px = Px + O.X
Py = O.Y - Py
If OPx = 0 Or OPy = 0 Then
picM.PSet (Px, Py), Color
OPx = Px
OPy = Py
Else
picM.Line (OPx, OPy)-(Px, Py), Color
OPx = Px
OPy = Py
End If
End Sub

Private Function Func(ByVal X As Single) As Single
Func = X ^ 2
End Function

Private Sub picM_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If isPointMove Then
shpPoint.Move X - 4, Y - 4, 9, 9
End If
End Sub

Private Sub picM_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If isPointMove Then
isPointMove = False
shpPoint.Visible = False
If MovingPoint = "O" Then
O.X = X
O.Y = Y
picM.Circle (X, Y), 1, Color
picM.Line (0, Y)-(picM.Width, Y), Color
picM.Line (X, 0)-(X, picM.Height), Color
End If
End If
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式