GDI+ supports two different forms of a complex curve that can't be represented as an arc of a circle or an ellipse: a cardinal spline and a Bézier spline. A cardinal spline is the curve that you would create by taking a piece of flexible material-such as a thin stripe of iron or wood-and making it pass through a given set of fixed points on the X-Y plane. Unless the material you're using is infinitely flexible (as it would be a string of rope or rubber), the path drawn by the material would be a curve that doesn't create any sharp angles at the connecting points. Depending on the degree of flexibility (also known as tension) of the material used, a given set of points can generate different curves. The default tension is 0.5. The following code snippet draws five cardinal splines, with a tension that goes from 0 (which corresponds to a material with infinite flexibility, which therefore draws straight lines) to 2:
' This statement assumes that you have imported the System.Drawing namespace
' This code should run inside a Windows Form class
Dim gr As Graphics = Me.CreateGraphics
Dim points() As Point = {New Point(100, 100), New Point(200, 200), _
New Point(250, 30), New Point(350, 100)}
Dim tension As Single
For tension = 0 To 2 Step 0.5
gr.DrawCurve(Pens.Blue, points, tension)
Next
gr.Dispose
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.