+ Reply to Thread
Results 1 to 6 of 6

Icon serving as button placed on top of shape inside user form

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Icon serving as button placed on top of shape inside user form

    Hi all,

    I'm trying to build a floating menu in Excel with shapes, icons and userforms. Basically I want to use an office icon as a button in a user form, but have it on top of a filled circular shape. The icon itself is a square with a white background. Is there a way to have it in the foreground and possibly even remove it's background to make it fade into the shape like you can do it with PNG images?

    So far I have successfully drawn the circular shape and I can change its colour, but as soon as I try to place anything on top of it, whether that's an icon or a control like a command button, it will always be hidden behind it (see image), rather than appear on the foreground. Does anyone know how to bring it to the front? There seems to be no ZOrder property for it.

    I found below post by Andy Pope, but he is only illustrating shapes on top of shapes not icons or controls on top of shapes.

    http://www.andypope.info/vba/userformdraw.htm

    Any help or hints would be appreciated
    Attached Images Attached Images

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Icon serving as button placed on top of shape inside user form

    at design time right click control and the popup menu has bring forward/send back options.
    Also the Format menu has Order sub menu.

    Note that some controls will always appear in front of other, such as Frame


    Non standard controls are not normally worth the effort. Why the need for a round button?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Icon serving as button placed on top of shape inside user form

    Unfortunately things are a little more complex than they seem initially. As you can see in my original post, the emoji icon is an "image" control from VBA and the button is the "commandbutton" control from VBA. With these two controls I can use the "bring forward/send back" option to set the order. However, the magenta filled circle is not a VBA default control, this one is inserted through API (mainly CreateWindowEX and CreateEllipticRgn API / inspired by Jaafar Tribak / see link below) and is inserted at runtime, hence I couldn't find a way to change its order.

    https://www.mrexcel.com/board/thread...erform.514521/

    With regards to why there's a need for a round button - I'm basically trying to replicate below floating menu in Excel that will serve for many purposes, hence definitely worth the effort if achievable. It's technically a rectangle with rounded corners though, not a circle, I just simplified it for demonstration purposes.
    Attached Images Attached Images
    Last edited by esbencito; 03-03-2021 at 03:59 AM.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,430

    Re: Icon serving as button placed on top of shape inside user form

    You attachment does not show anything.

    Rather than drawing to the form could you not use other controls to mask standard controls.
    This uses a label to handle happyface image and colour.
    The image control in front contains a transparent image to mask the label in order to make it appear round.
    image control is disabled so the label click event can be fired

    click the happy face to change colour
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Icon serving as button placed on top of shape inside user form

    Thanks for the draft. I also quickly mocked up a demo to illustrate what I am trying to achieve. In the file attached you will find two sheets, one that uses two user forms (desired visual output, except form of shape) and the other using just one (preferred, but more issues). Now there is two main problems: First, using one user form will make the icon overwrite the background colour of the shape when I make it transparent. Second, the shape needs to be a rectangle with rounded corners, but I don't want to use the method in your example as this makes the shape pixelated and I have to store the JPEG somewhere. I also want this to be more flexible and dynamic, so drawing/ importing shapes seems the better method than having to "fake" it with an image on top of a label.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Icon serving as button placed on top of shape inside user form

    See file attached
    Last edited by esbencito; 11-05-2021 at 12:34 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 10-01-2020, 05:40 AM
  2. Replies: 0
    Last Post: 09-28-2020, 12:05 PM
  3. [SOLVED] VBA to move form button and ActiveX Control button, Shape position
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2018, 02:46 PM
  4. [SOLVED] Help... Using a user form to show progress inside a loop
    By Andrew Entee in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-13-2017, 04:49 PM
  5. [SOLVED] User Form texbox calculation to return % icon after value.
    By Colin Smit in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-04-2014, 06:24 PM
  6. List inside of a user form
    By sentinela in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2009, 09:58 AM
  7. Retrieve Shape text when more than 255 characters inside shape
    By Wizz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-04-2009, 10:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1