+ Reply to Thread
Results 1 to 21 of 21

Userform with image control.

  1. #1
    Registered User
    Join Date
    08-07-2015
    Location
    Trondheim, Norway
    MS-Off Ver
    2013
    Posts
    11

    Userform with image control.

    Hi

    Please be patient with the grammar - English is not my native language.

    I try to digitize our injury form (I work as a ski patrol in a ski resort in my spare time).
    The idea is to use Excel with user form. But - I have a challenge I'm not sure is solvable.
    A part of the paper version of the injury form there is a sketch of a person. In the sketch, the relevant body part must be marked. With circle if visible damage and a cross if it only hurts.
    After marking, the idea is to save the image, and possibly be part of a printout.
    Is this solvable?

    The rest of the form I have control over. But it would have been incredibly stylish to get the sketch into the user form so that it was possible to mark a point with either a fixed circle or a cross.

    Regards
    Eternal optimist

  2. #2
    Forum Expert
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    2,293

    Re: Userform with image control.

    Small demo form attached, hope there is something there that you can use or expand upon.
    The two symbols ( X and O) are just standard labels with the background set transparent.
    The labels Z order is set 'fore' and the image box Z order is set 'back'.
    you can move the symbols by conventional drag & drop (mouse left key held down - move to location - mouse left key released to position).
    The form is set show modal false to enable you to press print key on sheet.
    Both files need placing together in the same folder.
    torachan.
    Attached Images Attached Images
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    08-07-2015
    Location
    Trondheim, Norway
    MS-Off Ver
    2013
    Posts
    11

    Re: Userform with image control.

    Thank you - that was very nice

    That was very close to what I want, so I would like to ask you for a favour. Can you please add a few extra features.
    1) An injury can be in several places on the body. I therefore need the opportunity to draw more circles or crosses out on the drawing.
    2) Save the drawing so that it can be part of a report.

    I'm a beginner at userforms, and looking at your code to learn. To make it easier for me, I hope you can add a field to the user form - eg a name. Then a command button that stores both name and selected image in an excel sheet, eg name in A1 and link to image A2.
    Then I have what I need to implement it in my own user form.

    Thank you
    Last edited by Trond64; 04-04-2021 at 02:56 PM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,574

    Re: Userform with image control.

    I hope torachan doesn't mind but I've updated the userform a bit.

    Now, you can now add a blue cross by left clicking on the image and a red circle by right clicking.

    You can also drag the added labels around and you can click the clear button to remove any added labels to start over.

    Not everything you want but it might help.
    Attached Files Attached Files
    If posting code please use code tags, see here.

  5. #5
    Forum Expert
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    2,293

    Re: Userform with image control.

    @Norie, that is good, I am struggling trying to save the image complete with the added crosses, any ideas how to keep the group together.
    torachan.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,574

    Re: Userform with image control.

    I'm not sure that's going to be possible - I can't find anything for grouping controls programmatically.

    One idea I had would be to have the image on a separate sheet and create labels on that sheet, placing them using the properties of the labels on the userform - see the attached file.

    It's not great but it kind of works and I'm sure it could be improved on.
    Attached Files Attached Files

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,574

    Re: Userform with image control.

    I've resized the image on the sheet and on the userform and this appears to work a bit better.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-07-2015
    Location
    Trondheim, Norway
    MS-Off Ver
    2013
    Posts
    11

    Re: Userform with image control.

    Thank you both
    I like v3.
    Only thing that is missing, and that is the commandbutton "Save".
    Suggestion: I think that when the markers are placed on the figure then the user can click save. Will it then be possible to take a screenshot of only the figure and save it with a given name and in a given catalog?
    All registrated injured have a unik case number, so maybe it could be the file name (000001.gif)?

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,574

    Re: Userform with image control.

    This version allows you to save the figure with the markers.

    Still need to add code to allow user to specify location/name etc.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    08-07-2015
    Location
    Trondheim, Norway
    MS-Off Ver
    2013
    Posts
    11

    Re: Userform with image control.

    Thank you

    The season for skiing is soon over, and the plan is then to complete the user form.
    As mentioned, I am a beginner who is trying to do something I do not have the skills to do. Hope I can get back to you with my draft and get help to the final finish.
    Have a nice day

  11. #11
    Registered User
    Join Date
    10-21-2019
    Location
    lugo
    MS-Off Ver
    2016
    Posts
    20

    Re: Userform with image control.

    Torachan and Norie, really nice concepts. I can imagine, as the first idea that came to my mind, that they would come very handy to report problems as surveyor,... and a lot more useful applications.
    I really appreciate the code and the idea.

    Following the original OP requirements, and the previous implementations the thing could evolve a little as following:

    Norie's v4 has a problem with clearing the form as it deletes the SHOW FORM button in the worksheet.
    I have rearranged the code to my own declarations... so it differs a little from Norie's version naming. Hope nobody gets angry with this.

    In the version attached, I have made some implementations, being the main where the mark is (pretty obvious from a drawing, but it comes handy to get converted to "text" and indexed in a database):
    1. there is a "section" creator, when you pick on the command button "get section coordinates", you can create a "new" section. I have not checked the code extensively, but I think it works quite wellç
      To end the section, click the button back. I should have implemented it with a Toggle Button. Aside from this, is working as expected.
    2. it finds where the mark is (if any section prevously created).
    3. you can delete any mark item with double click over it... It could be implemented with an undo, or get the item selected from selectable "control". For now, it's ok

    ToDo: any help on these, really appreciated:
    1. I have to delete the vertices of the sections once created... not too much time on it, as is a real mess with several sections
    2. Need to import the vertices of the sections from text file... so I can get it from any CSV/DXF/KML/SHP file
    3. Need to export the vertices of the sections to text file.
    4. Also, need to create a translucent polygon over the image with any section polygon created (this could only be achived via API declarations)... and activate it whenever the mouse gets inside section
    5. Get marks listed on a listbox/treeview/comboBox. From there, they could be selected and highlighted with double click
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    10-21-2019
    Location
    lugo
    MS-Off Ver
    2016
    Posts
    20

    Re: Userform with image control.

    I have forgotten... I have refined the position of the marks, and when they move, so now they are more centered on the click.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,574

    Re: Userform with image control.

    What exactly does the 'section' creator do?

  14. #14
    Registered User
    Join Date
    10-21-2019
    Location
    lugo
    MS-Off Ver
    2016
    Posts
    20

    Re: Userform with image control.

    The section (or region) creator generates HTML map like regions, by means of clicking the vertices of a virtual polygon. As yesterday it will take me too much time to get the polygon drawn in realtime I decided to upload the version that only shows the vertices while they are being inserted.
    Once the command/toggle button "Back to report" is clicked, stores the created vertices in an array of points, and asks user to give name to the region. For there on, every new mark injury inserted is checked against all already defined regions, and if any contains the point, it will explicit it on the "Location injury" label.

    I have worked a bit from version 4.1. Will upload probably today. Right now, implemented:
    - marks are deleted all with a click. Polygon vertices are removed once the "region creation" operation has finished.
    - contextual right-click menus (mainly copy-paste-delete-undo), with no functional code yet. I still have to depurate when a mark is deleted to rearrange all the Events array
    - Screenshot (that is different from "Save to Excel shapes"). Screenshot is stored on clipboard.
    - Yesterday I tried hard to get regions with the Windows APIs, but did not get too much luck with this, as the regions where clumsy, always above the Image control, and my tries to get them translucent/transparent were a real mess. Better not to show .

    I also worked a bit on drawing over the userform, but did not get to draw on the Image control properly, that should be the target chalkboard, the thing is that I have to work out how to get the hWnd of the Image control instead of the userform's one. But will get it done today.

    Final implementation I will try, is to get command buttons or even image controls instead of the labels. For production are "better" controls, as they can be located more precisely and can show images instead of only text.

    I probably will insert a very basic DXF load/export module, so it can be shown in a CAD software.

    And with these I should get finish with this thread.

  15. #15
    Registered User
    Join Date
    10-21-2019
    Location
    lugo
    MS-Off Ver
    2016
    Posts
    20

    Re: Userform with image control.

    The active version right now
    Attached Files Attached Files
    Last edited by audeser; 04-11-2021 at 01:05 PM.

  16. #16
    Registered User
    Join Date
    08-07-2015
    Location
    Trondheim, Norway
    MS-Off Ver
    2013
    Posts
    11

    Re: Userform with image control.

    Hi, and thank you so much for contributing.

    I am impressed with the help I receive, which has long been far above my level of knowledge.
    This it's starting to look like what I was hoping for
    I'm not sure if I can ask for anything more, but I'm trying.

    1: User form fails when I click "clear", and there is a circle on the figure. Is it possible to fix it?

    2: I looked at the code, but I do not understand file saving.
    What I envision is a sheet where a row is an injury. Each row is numbered (0001, 0002, etc.).
    Then it is desired that the figure is saved, for example, with number and year: "C: \ DATA \ SkiPatrol \ Injuries \ 0001_2021.jpg". In addition, a link to this file is added to the relevant row in the spreadsheet (same row as the name of the injured person, place of injury, date, how, etc.).
    Is it difficult to achieve?

    Then I think I will be able to use the code in the user form I am working on, and use it from next season as a member of Skipatruljen. That would have been cool.

    Thank you

  17. #17
    Registered User
    Join Date
    10-21-2019
    Location
    lugo
    MS-Off Ver
    2016
    Posts
    20

    Re: Userform with image control.

    Working on version 4.3. All points in list could be easily achieved somehow.

    As stated on post #14 there is an unsolved issue with the mark deleting process (one or all of them), as the array of events does not get actualized once the deletion occurs. Did not solve on version as I was considering how I would proceed with deleted data on my own development. But there should be a way to name/rename injuries.

  18. #18
    Registered User
    Join Date
    10-21-2019
    Location
    lugo
    MS-Off Ver
    2016
    Posts
    20

    Re: Userform with image control.

    So here's a new iteration. Now, is somehow universal, in the sense that code can be applied to any userform (controls are linked to specific parent userform, silently by its name, without designer intervention), and so the Events array has generic declarations in code.
    Also changed the operation controls, implementing command buttons and images as marks (although comment to not interfere). I was interested in command buttons, now is default. Clicking on the "X" command button will change to "O" and viceversa, so the initial functionality is still there. Have only to uncomment block to recover the "through labels operation". On the other hand, using image controls, could reduce, if done properly, the task to provide name and link to marks by means of user typing.
    As per the file saving procedure, not implemented. I think Norie's version saved to desktop, but I ripped it. You must explore how you wanna change it based on your needings, its' basic programming no matter the developer proficiency in VBA.
    I do not get anymore error with the "Save" after deleting. I can barely remember what I have coded these days, but it's not raising error. Yet, the numbering index is not corrected, so there is still a problem to solve, IMO.
    Got the transparencies working, but the code is cumbersome, and only fancy for rectangular shapes, as with irregular polygons it fills regions with black color, so I ripped the module from the code. I suppose my problem is with the display content handle, but I considered does not worth the time to explore.

    I'm done with this project right now. Maybe if in the future I need it will evolve. But there is plenty to complete:
    • A comboBox/ListBox operation code is not implemented.
    • Links to file images code is not implemented
    • Screenshot should reduce the size of the userform to the image control, and then restore, so that the capture is clean.
    • Debug the "thing" with the arrays when a control is removed.

    Now I'm moving to get an image browser, ACDSee alike, on a UserForm, in order not to exit the main application to search for a photo. Could fit here very nice, but this is another battle.
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    10-21-2019
    Location
    lugo
    MS-Off Ver
    2016
    Posts
    20

    Re: Userform with image control.

    The resize of the userform for a clean screenshot capture can be done modifying this little code to ge inside the userform, mainly setting own Userform , CommanButton1 control and Image control names to their correct value.

    This code also lets select a picture to be loaded inside the desired image control from the user Images folder, so it acts as a fast browser for photos, but setting the .InitialFileName =... line to another value, will get from specific folder

    Please Login or Register  to view this content.
    And there is chance to drag & drop files from explorer to a ListBox, as detailed in this post: https://www.mrexcel.com/board/thread...0/post-5673750, just pick the code as needed.

  20. #20
    Registered User
    Join Date
    10-21-2019
    Location
    lugo
    MS-Off Ver
    2016
    Posts
    20

    Re: Userform with image control.

    Even better, to manage the screenshot captures, it would be to manipulate via the STEPHEN BULLEN's PastePicture function. I do not post the associated Stephen Bullen code as is freely avaliable on the web.

    Then, the code on the userform should be like this to work:
    Please Login or Register  to view this content.
    The code comented could save the stdOLE pic to file. You can give the name you want to image.
    The code that is active will load the stdOLE pic on the Image1 control of the userform.

  21. #21
    Registered User
    Join Date
    12-08-2020
    Location
    unknown
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Userform with image control.

    that is what i hopeful find thread. thank you audeser

    i have an question about your replies,

    is it possible add tag by x, y coordinate not by clicking?

    i want to 2 value of txt_xpos, txt_ypos, and press button the cmdbutton (which is "O", "X" in your code") geneated on the image?

+ 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. Get Image from worksheet to UserForm Image Control
    By sijostephen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2020, 06:54 AM
  2. Generic Sub for Image control in Userform
    By smjjvh in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-15-2014, 05:46 PM
  3. Zoom plot in image control box present in the userform
    By HinaSha in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 05-04-2014, 12:26 AM
  4. [SOLVED] VBA to transfer image FROM userform image control TO a worksheet cell
    By Zoediak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2014, 02:51 PM
  5. [SOLVED] show jpeg picture inside a userform image control box
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 07-29-2013, 03:44 PM
  6. [SOLVED] Displaying a random image (or control) on a userform?
    By Jon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2006, 01:25 PM
  7. [SOLVED] Userform Image Control and embedded images
    By tim in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-05-2005, 09:06 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