Results 1 to 6 of 6

Thread: creating a shape at runtime **RESOLVED**

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    creating a shape at runtime **RESOLVED**

    Does anyone know how to create a shape at runtime

    user enters x1,y1,x2,y2 and shape in text boxes and the shape appears on the form.
    Last edited by davidrobin; Mar 13th, 2003 at 07:44 AM.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Make an array of shapes, then you can load them at runtime...

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    This code originally appeared in a post by toughcoder. I have just modified it a little.

    OK, I have done this but I get a 'Object variable or with block variable not set'

    Code:
    Option Explicit
    
    Dim blnDrawing As Boolean
    Dim x1 As Single, y1 As Single
    Dim Shape2(1) As Shape
    
    Private Sub Form_Load()
    '    Shape2.FillStyle = vbFSTransparent
    '    Shape2.FillColor = 0
    '    Shape2.BorderStyle = 1
    '    Shape2.BorderWidth = 1
    End Sub
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        x1 = X
        y1 = Y
        Shape2(0).Left = x1
        Shape2(0).Top = y1
        blnDrawing = True
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If blnDrawing = True Then
            Shape2(0).Width = X - x1
            Shape2(0).Height = Y - y1
    
        End If
    End Sub
    
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        blnDrawing = False
        Shape2(0).FillStyle = vbFSSolid
        Shape2(0).FillColor = vbRed
        Shape2(0).BorderColor = vbRed
    End Sub

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Sorry, I can't test this now(no IDE in my office), but
    Put a shape on the form at designtime(.index=0)

    at runtime use
    VB Code:
    1. shape(1).load

    I hope that'S correct!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    This thread kind of answered it for me

    http://www.vbforums.com/showthread.p...1&goto=newpost

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    ....LOL...nice bug with the visiblity....I remember the first time I did that...

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