drawing in picture box

dynamically_pro
09-07-2006, 02:04 PM
hello,
I moved from vb 6 to vb.net 2005 and having trouble with a small game I am making I need to code to draw lines in a diagonal directions 4 ways.
I attached my project and if anyone can code one of my CMD diagonal buttons, with plenty of comments I sure appreciate it. thanks

Gruff
09-07-2006, 02:42 PM
Welcome to the forum. Be sure to read the forum ..

This shouldn't be all that difficult.
Have you looked at the examples for line drawing with VB.NET help?

You derive a graphics object off of the picturebox then use its methods.

Public Class Form1

'Create a Picturebox and a button on a form then insert this code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oGraph As Graphics = PictureBox1.CreateGraphics
Dim x1, y1, x2, y2 As Single

x1 = 10.5
y1 = 10.5
x2 = 100.5
y2 = 100.5

With oGraph
.DrawLine(Pens.BlueViolet, x1, y1, x2, y2)
.DrawLine(Pens.BlueViolet, x2, y1, x1, y2)
End With
End Sub
End Class


BTW you need a few more posts before you get the ability to attach files.
~T

dynamically_pro
09-08-2006, 07:52 AM
Hello,
Thanks for the response. I read the rules, but didn't see anything about having a few post before I can attach something. I just read that size and what can be attached, so If I missed that part sorry about it. I will try the code and see how it goes, and report back. I am trying to make a small snake game to learn how draw lines using buttons, Like up, down, left, right, and diagonal.

Hi again,
ok I figured part of the program out
here is what I have for each cmd buttons except for 2 of the diagonals buttons which I am stuck on. Can't seem to get them to work.

Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
intXFactor = 0
intYFactor = 1
End Sub

Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
intXFactor = 0
intYFactor = -1
End Sub

Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click
intXFactor = -1
intYFactor = 0
End Sub

Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click
intXFactor = 1
intYFactor = 0
End Sub

Private Sub btnLeftDiagonal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeftDiagonal.Click
intXFactor = -1
intYFactor = -1

End Sub

Private Sub bntRBDiagonal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntRBDiagonal.Click
intXFactor = 1
intYFactor = 1
End Sub

The buttons that go rightLeft diagonal and leftBottom diagonal, I can't seem to get to work.

Gruff
09-09-2006, 02:42 PM
1) I assume you have the actual code for drawing your lines as you do not post it here.

2) I assume you know that positive Y is down in the default Windows coordinate system.

3) If you are trying to make diagonal movements then there are four of them just like there are four orthographic movements.

The only difference is that the diagonals all would be some form of (1,1) positive or negative. Think of them as eminating from a center point as you would the normal movements.

(1,1) to bottom right
(-1,1) to bottom left
(-1,-1) Top Left
(1,-1) Top Right

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum