Results 1 to 11 of 11

Thread: Object layering question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    20

    Question Object layering question

    I am trying to draw a line on top of a picturebox but it keeps going behind the picturebox, even when I do Line.BringToFront()

    Can someone help me with this?

    Thank you,
    CampSoup1988

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Object layering question

    If you are trying to draw the line ONLY on the picturebox, then you would draw the line onto the image from the picturebox. The easiest way to do that would be to draw it in the Paint Handler, since the e argument gives you a graphics object and you can then use the .DrawLine method.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    20

    Re: Object layering question

    No, currently I am doing a Tic Tac Toe program, so I am drawing a line to show the three positions that match, and the line will overlap the three pictures

  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Object layering question

    I'm assuming your picture box contains only an image, in which case you may not need the picture box at all: draw your images on the form/control which hosted those pictureboxes.

    With everything drawing to the form, you can draw your lines/images, etc. in any order you like.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    20

    Re: Object layering question

    how would you do this? As far as I know you could only have a background image (centered, stretched, tiled, etc)

    I admit, the last time I made a TicTacToe program was 5 or 6 years ago using VB6, also I have only used VB 2008 occasionally in the last couple years, so I am a bit rusty on it.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Object layering question

    How many PictureBoxes do you have? One for each square in the game? If so then you will need to do the same drawing on multiple controls, i.e. at least three PictureBoxes and also the form, if there is a gap between adjacent PictureBoxes. I've posted code to do this in the CodeBank, so follow the CodeBank link in my signature and find the thread dedicated to drawing the same picture on multiple controls.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Object layering question

    Quote Originally Posted by campsoup1988 View Post
    how would you do this? As far as I know you could only have a background image (centered, stretched, tiled, etc)

    I admit, the last time I made a TicTacToe program was 5 or 6 years ago using VB6, also I have only used VB 2008 occasionally in the last couple years, so I am a bit rusty on it.
    In stame way you would draw a line on a control (e.Graphics.DrawLine method in a Paint event, for example) you can draw an image using the DrawImage method of the graphics object.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    20

    Re: Object layering question

    Quote Originally Posted by SJWhiteley View Post
    In stame way you would draw a line on a control (e.Graphics.DrawLine method in a Paint event, for example) you can draw an image using the DrawImage method of the graphics object.
    Im used to using imagebox for images even in VB6.

    Im currently looking into jmcilhinney's sample (I had both router then comp issues these past few days)

    UPDATE: jmcilhinney, are you referring to THIS tutorial? If so, could you explain it a bit to me, like how to paint an image?

    I never used the paint methods before
    Last edited by campsoup1988; Jan 8th, 2011 at 06:20 PM.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Object layering question

    Yes, that's the thread I was referring to. SJWhiteley has already told you how to draw an Image in their previous post, that you just quoted. To draw a line you call DrawLine and to draw an Image you call DrawImage. The Graphics class has numerous DrawX methods and FillX methods to draw various things and fill various shapes. You should read the documentation for the Graphics class to see what methods are available. Note that most are overloaded to allow you to control various aspects of the drawing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    20

    Re: Object layering question

    ah, I wasnt sure since the tutorial seemed to only do line...

    Thanks.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Object layering question

    Quote Originally Posted by campsoup1988 View Post
    ah, I wasnt sure since the tutorial seemed to only do line...

    Thanks.
    It isn't a tutorial. It's an example. An example provides a single usage of a pattern to show how the pattern works. You can then apply that pattern to any other similar situation. As I posted in the thread:
    You can use a similar pattern to draw any "picture" you like on your form. The important part is the use of PointToScreen and PointToClient to convert coordinates from the form's frame of reference to that of the control currently being painted.
    The pattern is:

    1. Attach the same Paint event handler to every control you want to draw on.
    2. In the event handler, get the area that describes the drawing relative to the form.
    3. Translate that area relative to the control whose Paint event is being handled.
    4. Draw your "picture" using that area.

    That last step means calling any one or more methods of the Graphics class, which is how you draw using GDI+. Any information about GDI+ drawing is relevant to that part. If you want actual tutorials, there are some on GDI+ on the web.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width