The question of drawing lines and
shapes on a userform comes up quite often.
The normal approach for straight horizontal or vertical lines is to use
the border of a label control and set its height or width to 1.
When it comes to anything more fancy then the approach is to create the
drawing on the worksheet using the built-in auto-shapes and then at
design time manual copy and paste it to an image control's picture
Or for the brave you could go down the API route.
I have taken the auto-shape route.
The main differences being that shapes can be added at run time and
multiple shapes can be handled.
Shapes can be created and formatted as required before they are painted
to the userform.
The example above is a very gaudy
example of what is possible.
Here is the syntax used to create the
Set shpTemp = m_objDrawing.Box(10, 10, 40, 30)
If Not shpTemp Is Nothing Then
shpTemp.Fill.ForeColor.SchemeColor = 12
As you can see it is very similar to
normal VBA code used when adding and formatting auto-shapes.
I have included two versions of the
same demonstration for down loading.
One version contains all the modules and class code within a project. It
makes seeing the demonstration easier but requires extra work sharing
the code if used on other projects.