How can I draw simple X and Y axes?
And how can I set my point 0 on another place?
Could someone give me the codes for it?
thx
Printable View
How can I draw simple X and Y axes?
And how can I set my point 0 on another place?
Could someone give me the codes for it?
thx
Hi,Quote:
Originally Posted by Gleba
Here's a link about the X and Y axes;
http://msdn.microsoft.com/library/de...transforms.asp
Hope it helps,
sparrow1
if i use this code
Private Sub YGrid _
(ByVal GridColor As Color, ByVal AxisColor As Color, _
ByVal LabelColor As Color, ByVal LineWidth As Double)
Dim lLine As GraphicsPath
Dim lGridPen As New Pen(GridColor, LineWidth / 4.0)
Dim lAxisPen As New Pen(AxisColor, LineWidth)
For Each i As Integer In AxisPoints(mMinY, mMaxY)
lLine = New GraphicsPath
lLine.AddLine(New PointF(mMinX, i), New PointF(mMaxX, i))
If i = 0 Then
mGraphics.DrawPath(lAxisPen, lLine)
Else
mGraphics.DrawPath(lGridPen, lLine)
End If
DrawString(i.ToString, New PointF(0, i), LabelColor)
Next i
End Sub
i can't get it to work, I don't know where to put it in. Do I need to put it in the sub form or what? I don't know.
any code to draw on a form should be done in the forms paint event.
you can draw on the form in any routine by creating a graphics object from the form class like this..
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim G As Graphics = Me.CreateGraphics G.DrawString("HELLO WORLD", Me.Font, Brushes.Black, 0, 0) G.Dispose() End Sub
However as soon as your form is repainted (minimized and the restored, moved off screen then back on, or another window comes on top of the apps window), the string that was drawn will be gone.
If you put the drawing code in the forms paint event, it will be drawn everytime the form is repainted.
Also in the forms paint event, you can use e.Graphics that is passed in as a parameter, instead of using Me.CreateGraphics.
thx, but i still don't know how i can use this code.
Private Sub YGrid _
(ByVal GridColor As Color, ByVal AxisColor As Color, _
ByVal LabelColor As Color, ByVal LineWidth As Double)
Dim lLine As GraphicsPath
Dim lGridPen As New Pen(GridColor, LineWidth / 4.0)
Dim lAxisPen As New Pen(AxisColor, LineWidth)
For Each i As Integer In AxisPoints(mMinY, mMaxY)
lLine = New GraphicsPath
lLine.AddLine(New PointF(mMinX, i), New PointF(mMaxX, i))
If i = 0 Then
mGraphics.DrawPath(lAxisPen, lLine)
Else
mGraphics.DrawPath(lGridPen, lLine)
End If
DrawString(i.ToString, New PointF(0, i), LabelColor)
Next i
End Sub
You see I'm trying to draw the x and y axe and maybe the z axe to. But I would like to do it in a picturebox.
Also I would like that i can change the point(0,0) in the center of the picture box.
From what I understand, would I be correct in saying that you have no idea what that code actually does that you are using?
If so, you really must start with the basics of what and how to draw simple stuff, like lines, circles etc. Learn what the objects do, learn how to call them, learn how to change them.
If you have already done this, then ignore me :).