Display a Powerpack RectangleShape at runtime

Posted on 2009-05-08
Last Modified: 2012-05-06
The generation of the shape is controlled at runtime by data read from a file to set all the properties I care about e.g. Size, Location, Color, BorderWidth etc. Now, I would like to render it on a form. This should be trivial, but I can't just add it as a control so something different must be done...

Do I need to create some container on the form first, am I missing one of the commands to cause it to draw and/or connect it to a specific form, something else?? Probably a dumb question...
Dim rc As RectangleShape

        rc = New RectangleShape

        rc.Location = New Point(100, 100)

        rc.Size = New Point(150, 150)

        ' ... now what

Open in new window

Question by:MarkBottomley
LVL 16

Accepted Solution

ToddBeaulieu earned 125 total points
ID: 24338912
Check this out:

I whipped this example up...
    Private Sub DrawRectangle()

        Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer

        Dim rect1 As New Microsoft.VisualBasic.PowerPacks.RectangleShape

        ' Set the form as the parent of the ShapeContainer.

        canvas.Parent = Me

        With rect1

            ' Set the ShapeContainer as the parent of the RectangleShape.

            .Parent = canvas

            .BorderWidth = 2

            .BorderStyle = DashStyle.Solid

            .BorderColor = Color.DarkBlue

            .CornerRadius = 5

            .FillColor = Color.LightBlue

            .FillStyle = FillStyle.Solid

            .FillGradientStyle = FillGradientStyle.ForwardDiagonal

            .FillGradientColor = Color.AntiqueWhite

            ' Set the location and size of the rectangle.

            .Left = 10

            .Top = 10

            .Width = 100

            .Height = 100

        End With

    End Sub

Open in new window


Author Closing Comment

ID: 31579566
The addition of a Canvas is not obvious when just adding the PowerPack items in the form designer - thanks

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now