I'm fairly new to VB.NET.
I'm making a program where I have to draw shapes using the e.Graphics Class, and not using PowerPacks. I have been looking for a way to reference the created Object, to modify them, or to use their values. I was wondering if anyone could help me on this.
e.Graphics.DrawLine(Pens.Black,20,40, 60, 40)
dim temp as ::Something::
temp = e.Graphics.DrawLine(Pens.Black,20,40, 60, 40)
e.Graphics.DrawLine(Pens.Black, temp.X2, temp.Y1, temp.X2+ 45, temp.Y1)
There is no
Object since you're just drawing, but you can use points or create your own structure which contains the coordinates of the lines you're drawing
Using the Point structure:
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim p1 As New Point(20, 40) Dim p2 As New Point(60, 40) e.Graphics.DrawLine(Pens.Black, p1.X, p1.Y, p2.X, p2.Y) e.Graphics.DrawLine(Pens.Black, p2.X, p1.Y, p2.X + 45, p1.Y) End Sub
Using a custom structure:
Public Structure lineCoords Public x1 As Integer Public x2 As Integer Public y1 As Integer Public y2 As Integer End Structure Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim _lineCoords1 As New lineCoords With _lineCoords1 .x1 = 20 .y1 = 40 .x2 = 60 .y2 = 40 End With e.Graphics.DrawLine(Pens.Black, _lineCoords1.x1, _lineCoords1.y1, _lineCoords1.x2, _lineCoords1.y2) Dim _lineCoords2 As New lineCoords With _lineCoords2 .x1 = _lineCoords1.x2 .y1 = _lineCoords1.y1 .x2 = _lineCoords1.x2 + 45 .y2 = _lineCoords1.y1 End With e.Graphics.DrawLine(Pens.Black, _lineCoords2.x1, _lineCoords2.y1, _lineCoords2.x2, _lineCoords2.y2) End Sub