Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding and moving images in a running form

Filip Brnic

Programmer
Dec 25, 2023
66
RS
Hello, before i even dug dipper into this because i had an idea, is it even possible to do so.
My idea was that i can have a command button that will insert little icons of some characters(depending on the name typed in a corresponding text box) as 30x30 images, and than i could move them around on a form. Is it even possible to afterward save that form and have it layed out the exact same way ive left those images?

I know there is probably a better program for doing this but i'd love for it to be done in fox because i have some tables that ill connect to that form later so its easier for me to do it in fox. (if possible)
 
You could do that, but the best way would be to put that as data. Which means each image you put on a form gets a record consisting of image filename, and left and top position and width and height. And then you can recreate a form starting from a blank form (or any base form) by adding these images from the data.

You should always first think of data.

The good news is that's nothing for which you need a special other programming language, that's totally within VFP capabilities without problem, as data is not a problem, is it?
 
Thanks for the fast answer Chriss, i had planned to have like around 150 images in my folder for that one form, and id add a search engine so you can select which one to add next, basically by typing in the textbox, or opening that folder and selecting the image, its not exactly that the images need to carry any data nor be connected to anything, i just kinda need them on the form, and i would need data for other stuff, basically the use of moving images is gonna be just to create like a list, and so when i arrange the images in a certain part of the list, next to it i would add some text/something that i already have stored in a table. But if its still fine to do what you suggested, could you guide me to some website or where in the visual fox pro help catalogue could i find examples.
 
drag and drop can be done in VFP in two ways, the OLE drag&drop way and the VFP drag&drop way. How to drag objects is demonstrated in the solutions project.
Hey thanks, i was writting a response for the first comment so i didn't even get this one, ill look into this!
 
All of the adding images and saving the position of them is fairly easy, it's all data. For example when it comes to saving you can just iterate through all the applicable controls on the form, capturing the position (Left, Top) and storing that in the manner that you require, for loading later.

You can drag controls around a form without too much difficulty, if the DragMode property of the control is set to 1 = Automatic Drag then you get the dragging part very easily. You can then tell the form to reposition controls after the Drag has finished by putting:

Code:
oSource.Move(nXCoord, nYCoord)

...after the parameter statement in the form's DragDrop method. It only takes about 2 minutes to create a test form, put an image control on it, set the DragMode property accordingly and add that code on the form, save and run and you can see how easily you can drag controls around a form and then you can make it more mature and specific to your requirements.

There are some quirks and there is some decent documentation on the subject. Look in the "Creating Drag-and-Drop Controls" topic in the help. An online copy of that particular topic is here: https://www.vfphelp.com/help/_5wn12p4im.htm
 
Instead of using a textbox to determine the image, you could provide a lower section of the form that provides the images that are available. This image list could be scrollable and a user would select an image and then drag to the location desired. I ditto the use of a table to manage the images selected and the position. If this is by user (each user can have their own layout) then also include the user Id in the table. If multiple layouts are possible, then you could still have a single form with a drop-down to select the user's specific layout. When saving the layout, include a description of the layout.
 

Part and Inventory Search

Sponsor

Back
Top