Answer» Alright I have Visual Studio 2005 professional.
I was about to start a new (well, I want to redesign one of my older games...) project in VB6, and then I figured that if I started it in VB .NET I'd have a reason to use Vb.NET (I had yet to do anything more than extremely basic tinkering).
I'll spare everybody from the laydown of my object heirarchy, but what I need is a graphics context form a picturebox. I cannot seem to find it. I'd expect something like PictureBox1.GetGraphics() like Java or just a Graphics Property.
can anybody point me in the right direction?
I know I can GET a Graphics Object by waiting for a Paint() even in the picturebox, but I'd prefer to set up double-buffering when the APP starts, rather then when the picturebox first paints. Well, I solved my own problem. personally I think it is a bit kludgy-
What I did was initialize the backbuffer in the Paint Event of the picturebox, using a local static to track the fact that I have already initialized it. And in the Else clause of that If Block I Call the Render() Method of the Graphics context.
So I fixed my problem, but now I'm confused! In VB6 you could Pset, Line, etc whenever you desired, there was no requirement to do so only within the paint event. Is this a new restriction, or am I overlooking some other method (pardon the pun) of getting the Graphics Object?You're overlooking the simple method. What you need to do, is draw a picturebox or object box (or anythign for that matter but i use one of thos) in the background of where you want your picture. Then you ned to create a new pen using the command
Dim myPen as new Pen(Color.Red) myPen.Width = 5
Of course, you can use any other colour and width. Now you need a place to draw (here is my picturebox)
Dim g as Graphics = Picturebox.CreateGraphics
Then you can draw things! Here's a few examples.
g.DrawLine(myPen, 1, 1, 45, 65)
g.DrawBezier(myPen, 15, 15, 30, 30, 45, 30, 87, 20)
g.DrawEllipse(myPen, New Rectangle(33, 45, 40, 50))
Etc
There are many others.
For anything more advanced, feel free to post here or in
http://z15.invisionfree.com/ISURA_Solutions
Have a good day.Oh OK, so it was the "createGraphics" method that I was looking for.
I had a strong feeling I was missing something! I was looking for either a property named "Graphics" or canvas, or a method like GetGraphics.
what I am doing is re-writing a VB6 Game I wrote ages ago to VB .NET. It's a arkanoid clone. Right now I am just starting to lay out the object heirarchy. What I'm doing is implementing a "Normal" Block as the Base Class for extending/Creating new blocks. What I'll have is the rendering CODE that will loop through the blocks and draw them (at level set-up), by calling the Draw() method, which accepts a GraphicsBuffer object.
So I guess the NEXT time I get a chance I CAN add the backbuffer initialization code to Form_Load like I originally tried. I couldn't find anything in the object browser, but I must not have looked hard enough.
Thank you for the help!
|