Home All Groups Group Topic Archive Search About

Simple Graphics Question

Author
1 Mar 2006 8:44 PM
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.

Author
1 Mar 2006 8:55 PM
AlanT
Try using the CreateGraphics() call from the picturebox

e.g.

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


hth,
Alan.
Author
1 Mar 2006 9:18 PM
Chris
AlanT wrote:
>
> 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
Author
2 Mar 2006 2:08 AM
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.


Show quoteHide quote
"Chris" <no@spam.com> wrote in mes?sage
news:u6m$GWXPGHA.3264@TK2MSFTNGP11.phx.gbl...
> AlanT wrote:
>>
>> 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
Author
2 Mar 2006 2:21 AM
I Don't Like Spam
fripper wrote:
Show quoteHide quote
> 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.
>
>
> "Chris" <no@spam.com> wrote in mes?sage
> news:u6m$GWXPGHA.3264@TK2MSFTNGP11.phx.gbl...
>> AlanT wrote:
>>> 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
>
>

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
Author
2 Mar 2006 12:26 AM
Dennis
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.
--
Dennis in Houston


Show quoteHide quote
"fripper" wrote:

>
> 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.
>
>
>
>