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
Printable View
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
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.
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
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.
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.
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.
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
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.
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:The pattern is:Quote:
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.
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.