locked
Drawing Rectangle Shape at Runtime

    Soru

  • I am drawing multiple rectangle shapes at runtime based on a XY location co-ordinate that I calculate.  The problem I have is the sometimes, one rectangle location is based off a previously calculate rectangle.

    How can I access the location of a rectangle that was generated at runtime?

    I have 1 routine that generates the shape.  How do I access the rectangle generated at runtime called BOX & i

    private sub Test()

                canvas.Parent = Me
                rect1.Parent = canvas
                rect1.Name = BOX & i
                ' Set the size of the rectangle
                rect1.Width = (LAYER_CASE_txtLength.Text * ScaleX)
                rect1.Height = (LAYER_CASE_txtWidth.Text * ScaleY)

    rect1.top = XXXX

    rect1.left = YYYY

     

    29 Eylül 2011 Perşembe 20:19

Tüm Yanıtlar

  • Your code is not complete. Where is the code for BOX & i? I cannot see the problem you got with the code above. Can you show the entire code?


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    04 Ekim 2011 Salı 03:20
  • I am drawing multiple rectangle shapes at runtime based on a XY location co-ordinate that I calculate.  The problem I have is the sometimes, one rectangle location is based off a previously calculate rectangle.

    How can I access the location of a rectangle that was generated at runtime?

    I have 1 routine that generates the shape.  How do I access the rectangle generated at runtime called BOX & i

    private sub Test()

                canvas.Parent = Me
                rect1.Parent = canvas
                rect1.Name = BOX & i
                ' Set the size of the rectangle
                rect1.Width = (LAYER_CASE_txtLength.Text * ScaleX)
                rect1.Height = (LAYER_CASE_txtWidth.Text * ScaleY)

    rect1.top = XXXX

    rect1.left = YYYY

     

    You may want to use a PictureBox for your graphics and a matrix for your rectangles (if your rectangles form a grid)

    So if your first rectangle is at the coordinates (i,j) and has the size (width1,height1), the rectangle that will come to the right will have the coordinates (i,j+width1) and the rectangle bellow should have the coordinates (i+height1, j).

    Also, you may find this tutorial on graphics useful.


    • Düzenleyen dheaven 01 Kasım 2011 Salı 12:43
    01 Kasım 2011 Salı 12:42