Simple Graphics Question

F

fripper

I have a VB 2005 app ... main window has a picture box control (picControl)
.... I want to draw a rectangle in that control using GDI+ ... something
like:

Dim g as graphics = creategraphics|()
Dim r as Rectangle
Dim b as new system.drawing.solidbrush(system.drawing.color.red)

r.x = 100
r.y = 100
r.width = 400
r.height = 50

g.fillrectangle(b,r)

How do I get the rectangle to appear in picControl and not the basic form
itself? Somehow I would like to tell the creategraphics function that I
want to put the graphics in picControl. Can I do that?

Thanks for any help.
 
A

AlanT

Try using the CreateGraphics() call from the picturebox

e.g.

Dim g as graphics = Dim g As Graphics =
Me.PictureBox1.CreateGraphics()


hth,
Alan.
 
C

Chris

AlanT said:
Try using the CreateGraphics() call from the picturebox

e.g.

Dim g as graphics = Dim g As Graphics =
Me.PictureBox1.CreateGraphics()


hth,
Alan.

Do it inside the OnPaint event of the picturebox if you want it to
redraw every time the picturebox refreshes. If you do it in there you
won't have to call CreateGraphics, it'll be passed to you as the event
argument.

Dim g as graphics = e.graphics

Chris
 
G

Guest

Also, you can create a bitmap the size of the picturebox, draw your rectangle
or what ever on the bitmap then assign the bit map to the picture box image
property.
 
F

fripper

Thanks for the help ... I am (slowly) learning VB 2005 graphics. Since you
were so good at answering that question I'll ask another one! I know that
with a bitmap object I can determine the color of an individual pixel by
using the getpixel method but is there some way I can determine the color of
a particular pixel in a picture box control?

Thanks.
 
G

Guest

fripper said:
Thanks for the help ... I am (slowly) learning VB 2005 graphics. Since you
were so good at answering that question I'll ask another one! I know that
with a bitmap object I can determine the color of an individual pixel by
using the getpixel method but is there some way I can determine the color of
a particular pixel in a picture box control?

Thanks.

I don't know how you would do that. I believe the way you want to do
that is "draw" onto a bitmap object that is shown in the picturebox.
You should be able to find some info on drawing to a bitmap by searching
your favorite engine.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top