Simple Graphics Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fripper

    #1

    Simple Graphics Question


    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(syst em.drawing.colo r.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.



  • AlanT

    #2
    Re: Simple Graphics Question



    Try using the CreateGraphics( ) call from the picturebox

    e.g.

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


    hth,
    Alan.

    Comment

    • Chris

      #3
      Re: Simple Graphics Question

      AlanT wrote:[color=blue]
      >
      > Try using the CreateGraphics( ) call from the picturebox
      >
      > e.g.
      >
      > Dim g as graphics = Dim g As Graphics =
      > Me.PictureBox1. CreateGraphics( )
      >
      >
      > hth,
      > Alan.
      >[/color]

      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

      Comment

      • Dennis

        #4
        RE: Simple Graphics Question

        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


        "fripper" wrote:
        [color=blue]
        >
        > 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(syst em.drawing.colo r.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.
        >
        >
        >
        >[/color]

        Comment

        • fripper

          #5
          Re: Simple Graphics Question

          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$GWXPGH A.3264@TK2MSFTN GP11.phx.gbl...[color=blue]
          > AlanT wrote:[color=green]
          >>
          >> Try using the CreateGraphics( ) call from the picturebox
          >>
          >> e.g.
          >>
          >> Dim g as graphics = Dim g As Graphics =
          >> Me.PictureBox1. CreateGraphics( )
          >>
          >>
          >> hth,
          >> Alan.
          >>[/color]
          >
          > 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[/color]


          Comment

          • I Don't Like Spam

            #6
            Re: Simple Graphics Question

            fripper wrote:[color=blue]
            > 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$GWXPGH A.3264@TK2MSFTN GP11.phx.gbl...[color=green]
            >> AlanT wrote:[color=darkred]
            >>> Try using the CreateGraphics( ) call from the picturebox
            >>>
            >>> e.g.
            >>>
            >>> Dim g as graphics = Dim g As Graphics =
            >>> Me.PictureBox1. CreateGraphics( )
            >>>
            >>>
            >>> hth,
            >>> Alan.
            >>>[/color]
            >> 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[/color]
            >
            >[/color]

            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

            Comment

            Working...