|
-
Jan 4th, 2011, 07:02 PM
#1
Thread Starter
Junior Member
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
-
Jan 4th, 2011, 07:19 PM
#2
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
 
-
Jan 4th, 2011, 07:22 PM
#3
Thread Starter
Junior Member
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
-
Jan 5th, 2011, 03:29 PM
#4
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."
-
Jan 5th, 2011, 09:09 PM
#5
Thread Starter
Junior Member
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.
-
Jan 5th, 2011, 09:12 PM
#6
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.
-
Jan 6th, 2011, 10:16 AM
#7
Re: Object layering question
 Originally Posted by campsoup1988
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."
-
Jan 8th, 2011, 05:53 PM
#8
Thread Starter
Junior Member
Re: Object layering question
 Originally Posted by SJWhiteley
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.
-
Jan 8th, 2011, 10:42 PM
#9
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.
-
Jan 8th, 2011, 10:44 PM
#10
Thread Starter
Junior Member
Re: Object layering question
ah, I wasnt sure since the tutorial seemed to only do line...
Thanks.
-
Jan 8th, 2011, 10:59 PM
#11
Re: Object layering question
 Originally Posted by campsoup1988
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|