Shapes on Userforms - A .borderthickness work around

tbrock

New Member
Joined
Feb 17, 2016
Messages
36
Hello again,

I have what I thought would be a simple task: placing a *real* shape onto a user form.

I know this topic has been discussed before and even many year ago. Scouring the net, I have seen two possible methods via:
  • Autoshapes: (thank you, Andy Pope) But (if I have not misunderstood) this does not draw the shape onto the userform. Rather it creates the shape off form and then copies an image of that shape onto the form. This would, then have the disadvantage of having properties (backcolor, forecolor, text, etc) that are not modifiable without recreating a new image at every change (and for every property).
  • API: (thank you, Jaafar Tribak). This does create "shapes" directly upon the userform, but is it limited to very basic shapes and (I believe?) without all the properties that the shape object would have.
That leaves me thinking the "amazing", that something that seems so obvious (to me, at least) - drawing shapes on a userform - is not truly possible? I'd have thought this functionality would have been an obvious checklist item in the creation of userforms. (sigh) If I am wrong and it is possible to draw a shape onto a userform, please help me acheive an epiphany! :)

In trying to work around this seeming limitation in my current application, I could get away with a standard form object (label, textbox,frame,etc) IF border thickness/width/weight were settable. But I have not found a single (userform) object to this point that has this property. So this is my question:

Is there a userform placeable object (that could emulate a shape) which has a settable border width/thickness/weight?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
- what is the purpose of the shape?
- how it will then be used in any code etc ?
- are you wanting to manipulate the object itself via code?
- is this what you want?

Userform shape.jpg
 
Upvote 0
This is not an easy task and the complexity of it depends on how many shapes you want to place on the userform at any one time as well as what you expect to do with the shapes as Yongle said.

You should be able to build on Andy Pope's approach by defining a Class object and assigning a Class instance to each "shape" image (The Class will create a Control at runtime to hold the "shape" image and will expose the specific Properties & Methods you need for modifying the "shape" image at runtime)
 
Upvote 0
@tbrock
The userform image in my previous post is a genuine snapshot
- the shape you see is a simple label with border setting fmBorderStyleNone and was inserted manually and contains no text

I should have asked ...
- how are required shapes manipulated, created or removed when userform is active?
 
Upvote 0
Thank you for the response! Here is a snap shot of what I am doing - basically a form to help format comments. Jaafar will recognize his work! There is also work from other kind folks here at Mr. Excel (shout out to Dataluver!). I currently am using a label to show a preview of what the comments will look like. As the label caption says, that means I cannot preview the autoshapes, border thickness, or margins. It is a single shape I would be using but it could have many property updates.

Although Andy Pope's method would work, my concern is the overhead involved. Thanks to Jaafar, each combobox that changes color immediately updates the label as the mouse scrolls. I have not tested it, but assumed that having to format a shape and then copy and paste it onto an image object every time there was a mouse scroll in one of those 4 comboboxes would be more "cost" than benefit. Though certainly since I would be using a true shape, I could show an exact representation of what the comments would like and all settings would be previewable.

So I thought a decent trade off in functionality would be if were some other control I could use that would allow me to show border thickness. Anyway, here is a snapshot of what I am doing:

Format Comments.PNG
 
Upvote 0
The simplest way
- clear all distractions like gridlines and row & column headers etc from worksheet
- make shape visible alongside the userform
- allow the user to watch the shape unfold
- use code to change the shape in the worksheet whenever the user modifies options

Userform and Shape.jpg
 
Upvote 0
Thank you, Yongle! I had tried going down that road... first trying to install a spreadsheet onto the userform. Then trying to move the underlying spreadsheet to a blank area where I could do just what you've shown. On my own, I failed. Seeing proof that it can be done, I will figure it out - I am stubborn that way. :)
 
Upvote 0
Positioning the userform relative to a cell is complicated - so I do not bother
If interested read: Form Positioner

Otherwise be lazy like me and use something that will probably work for most users
VBA Code:
Private Sub UserForm_Initialize()
    Me.StartUpPosition = 0
    Me.Top = ActiveWindow.Top + 150
    Me.Left = ActiveWindow.Left + 50
End Sub
 
Upvote 0
Thanks to @dataluver, I have coding for positioning a userform relative to a cell. However, I need to play and see if that gives the best results for this purpose or not. I like how your example looks with just a blank white background. At that point, cell location would be unimportant.
 
Upvote 0
I presume that you have already written the code to create a shape based on the options selected by the user
- use that to create the sample shape whilst the userform is active, triggered when specific values are changed or when "Refresh" button pressed
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,406
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top