Closed Thread
Results 1 to 9 of 9

Thread: VB Graphics Question (DrawLine)

  1. #1
    birko19 is offline Newbie
    Join Date
    Sep 2008
    Posts
    27
    Rep Power
    13

    VB Graphics Question (DrawLine)

    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?

    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
    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?

    Thanks in advance

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: VB Graphics Question (DrawLine)

    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?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  4. #3
    birko19 is offline Newbie
    Join Date
    Sep 2008
    Posts
    27
    Rep Power
    13

    Re: VB Graphics Question (DrawLine)

    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

  5. #4
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: VB Graphics Question (DrawLine)

    Yes, that is correct. I'm glad I could help, if you need anything else, just ask.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  6. #5
    birko19 is offline Newbie
    Join Date
    Sep 2008
    Posts
    27
    Rep Power
    13

    Re: VB Graphics Question (DrawLine)

    One more small question Xav, as I was playing around with this code, I've noticed that as I was changing the following:

    Dim Xvalue() As Integer = {400, 300, 400, 100}
    And then I was applying it in the following:

    gobj.DrawLine(pen, Xvalue(0), Yvalue(0), Xvalue(1), Yvalue(1))
    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?

  7. #6
    birko19 is offline Newbie
    Join Date
    Sep 2008
    Posts
    27
    Rep Power
    13

    Re: VB Graphics Question (DrawLine)

    I think I figured out my own question, but correct me if I'm wrong:

    Code:
    Dim Xvalue() As Integer = {400, 300, 400, 100}
    Dim Yvalue() As Integer = {100, 400, 100, 400}
    This declares the location points in an array of different points, and in here:

    gobj.DrawLine(pen, Xvalue(0), Yvalue(0), Xvalue(1), Yvalue(1))
    You're pretty much saying the following:

    Code:
     gobj.DrawLine(pen, 400, 100, 300, 400)
    Would that be correct?

  8. #7
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: VB Graphics Question (DrawLine)

    Exactly! The two variables are arrays.

    BTW, what are the last four values for in the arrays?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  9. #8
    birko19 is offline Newbie
    Join Date
    Sep 2008
    Posts
    27
    Rep Power
    13

    Re: VB Graphics Question (DrawLine)

    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.

  10. #9
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: VB Graphics Question (DrawLine)

    Ok.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. 3d Graphics in C#
    By DanDv in forum C# Programming
    Replies: 5
    Last Post: 04-12-2011, 01:47 AM
  2. Graphics in PHP
    By Vswe in forum PHP Tutorials
    Replies: 6
    Last Post: 03-21-2010, 08:03 PM
  3. C++ Graphics
    By Hunter100 in forum C and C++
    Replies: 3
    Last Post: 03-15-2010, 11:51 PM
  4. Graphics in VB.NET Part 2 - Graphics
    By Vswe in forum Visual Basic Tutorials
    Replies: 4
    Last Post: 11-07-2009, 06:03 PM
  5. Replies: 3
    Last Post: 09-10-2008, 06:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts