Results 1 to 5 of 5

Thread: Creating Shape in picturebox?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Davis, CA
    Posts
    23

    Post

    I have a program that makes creates a shape from a set of coordinates in a textbox, but i want it to put the shape as a part of a picture box instead of the form. Is this possible?
    Here is the code i have so far:
    Code:
    Public WithEvents myshape As Shape
    
    Private Sub Create_Shape()
    MyCoords = Split(Text11.Text, ",")
       Set myshape = Controls.Add("VB.Shape", "abc")
                myshape.left = MyCoords(0)
                myshape.top = MyCoords(1)
                myshape.width = MyCoords(2)
                myshape.height = MyCoords(3)
                myshape.Shape = 0
                myshape.BorderColor = &HFF00FF
                myshape.BorderWidth = 3
                myshape.Visible = True
    End Sub
    [Edited by sp007 on 11-29-2000 at 09:54 PM]

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    You could always draw them directly using the API, but I'm not sure if that is what you want. If it is let me know and I'll send some code.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Davis, CA
    Posts
    23
    I suppose that could work. Would you still be able to set the properties, such as borderwidth as bordercolor through api?

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    When drawing to a device such as a PictureBox the borderwidth and bordercolor are determined by the current properties of the surface you are drawing too, in this case the PictureBox, here is a quick example of how to draw a Rectangle.

    Code:
    Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    
    Private Sub Picture1_Paint() ' all drawing should be done in paint event 
     Dim lRet As Long ' return value from drawing function
        Picture1.DrawWidth = 2 ' same as borderwidth
        Picture1.ForeColor = RGB(255, 0, 0) ' same as bordercolor
        
        'draw rectangle
        lRet = Rectangle(Picture1.hdc, 5, 5, 50, 100)
        
    End Sub
    Also the api uses Pixels as coordinates rather than Twips so if you wanted to convert a Twip coordinate to a Pixel coordinate use this formula.

    Code:
        x = x / Screen.TwipsPerPixelX
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Davis, CA
    Posts
    23
    Excellent. Thanks a ton. It works Great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width