Hi, my first post here
I just started to learn graphics with programming (I'm also using C++ and C# with graphics but that's a different topic), my question is not so much on how to do it, but the understanding part of it, for example I have the following code, can anyone explain it to me exactly?
For the record, the output of this small is the letter "X" in the color white, but can someone please be kind enough to explain me the theory on how the X's and Y's work in this program?Code:Public Class Form1 Inherits System.Windows.Forms.Form Dim gobj As System.Drawing.Graphics Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click 'Set up the graphics object gobj = picBox.CreateGraphics() Dim Xvalue() As Integer = {100, 400, 400, 100} '<--Explain the 4 points. Dim Yvalue() As Integer = {100, 400, 100, 400} '<--Same as the above. Dim pen As New Pen(Color.White, 30) 'Can somone please explain the two lines below in detail, I understand 'that DrawLine function will draw with the following parameters, but 'I'm just having a hard time understanding the concept of how the 'X's and Y's are working. gobj.DrawLine(pen, Xvalue(0), Yvalue(0), Xvalue(1), Yvalue(1)) gobj.DrawLine(pen, Xvalue(2), Yvalue(2), Xvalue(1), Yvalue(1)) End Sub
Thanks in advance![]()
DrawLine() accepts a pen, which is the colour. Then, there are four parameters:
- the X co-ordinate of the starting point
- the Y co-ordinate of the starting point
- the X co-ordinate of the ending point
- the Y co-ordinate of the ending point
See?
Of course, stupid me
In other words these values make up the points of the line...
Thank you for the quick respont, now I can continue with my learning, cheers![]()
One more small question Xav, as I was playing around with this code, I've noticed that as I was changing the following:
And then I was applying it in the following:Dim Xvalue() As Integer = {400, 300, 400, 100}
I was getting a line popping up in different locations all the time, so now I understand that {400, 300, 400, 100} determine the location for the line, pretty much it's {X, Y (For the first point), X, Y(for the second point)}, now my question is what do the Xvalue(0) or Yvalue(0) exactly do? I know that the second code I have up there actually draws the line, but what are those parameters within the Xvalue and Yvalue for if the points are being determined in the decleration Dim area?gobj.DrawLine(pen, Xvalue(0), Yvalue(0), Xvalue(1), Yvalue(1))
I think I figured out my own question, but correct me if I'm wrong:
This declares the location points in an array of different points, and in here:Code:Dim Xvalue() As Integer = {400, 300, 400, 100} Dim Yvalue() As Integer = {100, 400, 100, 400}
You're pretty much saying the following:gobj.DrawLine(pen, Xvalue(0), Yvalue(0), Xvalue(1), Yvalue(1))
Would that be correct?Code:gobj.DrawLine(pen, 400, 100, 300, 400)
Those are just random values (For the X and Y values) within the array, I suppose I don't need them but the example I was looking at has them.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks