Graphics.DrawCurve 方法
重载
| DrawCurve(Pen, Point[]) | 绘制经过一组指定的 Point 结构的基数样条。 |
| DrawCurve(Pen, PointF[]) | 绘制经过一组指定的 PointF 结构的基数样条。 |
| DrawCurve(Pen, Point[], Single) | 使用指定的张力绘制经过一组指定的 Point 结构的基数样条。 |
| DrawCurve(Pen, PointF[], Single) | 使用指定的张力绘制经过一组指定的 PointF 结构的基数样条。 |
| DrawCurve(Pen, PointF[], Int32, Int32) | 绘制经过一组指定的 PointF 结构的基数样条。 从相对于数组开始位置的偏移量开始绘制。 |
| DrawCurve(Pen, Point[], Int32, Int32, Single) | 使用指定的张力绘制经过一组指定的 Point 结构的基数样条。 |
| DrawCurve(Pen, PointF[], Int32, Int32, Single) | 使用指定的张力绘制经过一组指定的 PointF 结构的基数样条。 从相对于数组开始位置的偏移量开 |
屏幕坐标系与常用数学的坐标系的转换有点难搞

Imports System.Math
Public Class Form1
Dim myGraph As Graphics
Dim myPen As New Pen(Color.Black, 3)
Private Sub Paintline()
myGraph = PictureBox1.CreateGraphics
myGraph.Clear(Me.BackColor)
myPen.Color = Color.Black
myPen.Width = 3
myPen.EndCap = Drawing2D.LineCap.ArrowAnchor
Dim Ox As Integer = Int((PictureBox1.Left + PictureBox1.Right) / 2)
Dim Oy As Integer = Int((PictureBox1.Top + PictureBox1.Bottom) / 2)
Dim Xleft As Integer = Int(PictureBox1.Left + 5)
Dim Xright As Integer = Int(PictureBox1.Right - 5)
myGraph.DrawLine(myPen, Xleft, Oy, Xright, Oy)
Dim Ytop As Integer = Int(PictureBox1.Top + 5)
Dim Ybottom As Integer = Int(PictureBox1.Bottom - 5)
myGraph.DrawLine(myPen, Ox, Ybottom, Ox, Ytop)
Dim LinePoints() As PointF
Dim SinPoints(Xright - Xleft) As PointF
Dim CurvePoints(Xright - Xleft) As PointF
If CheckBox1.Checked Then
ReDim LinePoints(1)
LinePoints(0) = New PointF(Ox + 150, Oy - 150)
LinePoints(1) = New PointF(Ox - 150, Oy + 150)
myPen.Width = 3
myPen.Color = Color.Red
myPen.EndCap = Drawing2D.LineCap.Custom
myGraph.DrawLine(myPen, LinePoints(0), LinePoints(1))
End If
If CheckBox2.Checked Then
Dim x As Integer
Dim x1 As Single
Dim y1 As Single
For x = 0 To Xright - Xleft
x1 = x
y1 = Oy - 80 * Sin((x - Ox) / 90 * PI)
SinPoints(x) = New PointF(x1, y1)
Next
myPen.Width = 3
myPen.Color = Color.Blue
myPen.EndCap = Drawing2D.LineCap.Custom
myGraph.DrawCurve(myPen, SinPoints)
End If
If CheckBox3.Checked Then
Dim x As Integer
Dim x1 As Single
Dim y1 As Single
For x = 0 To Xright - Xleft
x1 = x
y1 = Oy - (x - Ox) * (x - Ox) / 100
CurvePoints(x) = New PointF(x1, y1)
Next
myPen.Width = 3
myPen.Color = Color.Green
myPen.EndCap = Drawing2D.LineCap.Custom
myGraph.DrawCurve(myPen, CurvePoints)
End If
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Paintline()
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Paintline()
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
Paintline()
End Sub
Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
Paintline()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
本文探讨如何利用Graphics.DrawCurve方法在.NET中绘制函数曲线,重点介绍该方法的重载形式,并讨论屏幕坐标系与数学坐标系之间的转换问题。
6910

被折叠的 条评论
为什么被折叠?



