Hello all!
First post for me on these pages, so please be gentle.
My problem is as follows. I have a List(of Point) that stores the current mouse location coordinates when the user clicks inside a picture box. The picture box paint event then draws a small FillRectangle using those coordinates and does the same for each following click, as well as drawing a line between each point.
I used the following code in the picture box paint event to paint the rectangles and draw the lines:
All of the above works fine with no errors.
I've made four buttons (labeled Up, Down, Left, Right) and when clicked I'd like the rectangles and lines to move by 50 pixels in the chosen direction. I've tried to do this with the following code in, for example, the Up Button's click event:
This causes no errors, but no movement either. I put a Watch on pointsList and the coordinates aren't updating as I expected.
I've searched Google, and found a number of pages suggesting that using this method doesn't actually affect pointsList itself, rather a copy of pointsList.
I've been unable to find any explanation as to how I can modify an item's property when contained in a list using a For Each loop.
Anyone able to help?
Cheers,
Mark.
First post for me on these pages, so please be gentle.
My problem is as follows. I have a List(of Point) that stores the current mouse location coordinates when the user clicks inside a picture box. The picture box paint event then draws a small FillRectangle using those coordinates and does the same for each following click, as well as drawing a line between each point.
I used the following code in the picture box paint event to paint the rectangles and draw the lines:
VB.NET:
For Each p As Point In pointsList
e.Graphics.FillRectangle(Brushes.Blue, p.X - 2, p.Y - 2, 5, 5)
Next
Dim i As Integer = 0
If pointsList.Count > 1 Then
For i = 1 To pointsList.Count - 1
e.Graphics.DrawLine(Pens.HotPink, pointsList.Item(i - 1), pointsList.Item(i))
Next
End If
All of the above works fine with no errors.
I've made four buttons (labeled Up, Down, Left, Right) and when clicked I'd like the rectangles and lines to move by 50 pixels in the chosen direction. I've tried to do this with the following code in, for example, the Up Button's click event:
VB.NET:
For Each p As Point In pointsList
p.Y += 50
Next
PictureBox1.Invalidate()
This causes no errors, but no movement either. I put a Watch on pointsList and the coordinates aren't updating as I expected.
I've searched Google, and found a number of pages suggesting that using this method doesn't actually affect pointsList itself, rather a copy of pointsList.
I've been unable to find any explanation as to how I can modify an item's property when contained in a list using a For Each loop.
Anyone able to help?
Cheers,
Mark.