(Desktop) Display different pictures when certain item in Combobox picked.

Hello ,
Im trying to have it so when you pick t-shirt 29m in the combobox it displays a picture in a canvas. i can get it to display the picture only once and if i try and change it to Long Sleeve 29m it keeps the old picture there still. I’m not sure how to clear everything in the canvas to display the new image. kinda stuck atm. Here is what i have .
I have a Property named Front29M_S as Picture and the others are named to correspond with each picture.
Next i have in the Canvas paint event to handle resizing the image.

[quote] Dim scaleX, scaleY, scale as Double
Dim theLeft, theTop as integer

if Front29M_S <> nil then //Logo is a property that has been added to the window
if Front29M_S.width <= canvas5.width and Front29M_S.height <= canvas5.height then //if pic is smaller than the canvas
theLeft = (canvas5.width - Front29M_S.width)/2 //center the image horizontally
theTop = (canvas5.height - Front29M_S.height)/2 //center the image vertically
g.DrawPicture Front29M_S, theLeft, theTop
else
scaleX = canvas5.width / Front29M_S.width
scaleY = canvas5.height / Front29m_S.height
scale = Min( scaleX, scaleY ) //choose the smaller value
theLeft = (canvas5.width - (Front29M_S.widthscale))/2 //center the image horizontally
theTop = (canvas5.height - (Front29M_S.height
scale))/2 //center the image vertically
g.DrawPicture Front29M_S, theLeft, theTop, Front29M_S.width * scale, Front29M_S.height * scale, 0, 0, Front29M_S.width, Front29M_S.height
end if
end if

[/quote]
In my Combobox Change event i have the following which doesn’t work correctly . once you pick an item it won’t change to another picture.

[quote] Dim Front29M_File as FolderItem
Dim Front996_File as FolderItem
Dim FrontCrew562_File as FolderItem
Dim Front29M_LS_File as FolderItem

Front29M_File = GetFolderItem("/Users/tracynolte/Documents/InvoiceProgram/img/Garments/Front29M_S.png", FolderItem.PathTypeShell)
Front996_File = GetFolderItem("/Users/tracynolte/Documents/InvoiceProgram/img/Garments/Front996_S.png", FolderItem.PathTypeShell)
FrontCrew562_File = GetFolderItem("/Users/tracynolte/Documents/InvoiceProgram/img/Garments/FrontCrew562_S.png", FolderItem.PathTypeShell)
Front29M_LS_File = GetFolderItem("/Users/tracynolte/Documents/InvoiceProgram/img/Garments/Front29M_LS_S.png", Folderitem.PathTypeShell)

if Front29M_File <> nil and me.text = “T-Shirt 29M” then
Front29M_S = Front29M_File.OpenAsPicture //Uses the T-Shirt Picture and adds to window
if Front29M_S <> nil then
canvas5.refresh //forces the canvas to display the scaled image
elseif Front996_File <> nil and me.text =“Hoodie 996” then
Front996_H = Front996_File.OpenAsPicture // Uses the Hoodie Picture and adds to window
if Front996_H <> nil then
Canvas5.EraseBackground = true
Canvas5.Refresh //forces the canvas to display the scaled image
elseif Front29M_LS_File <> nil and me.text = “Long Sleeve 29LS” then
Front29M_LS = Front29M_LS_File.OpenAsPicture // Uses the LongSleeve Picture and adds to window
if Front29M_LS <> nil then
Canvas5.Refresh //forces the canvas to display the scaled image
elseif FrontCrew562_File <> nil and me.text = “Crew Neck Sweat Shirt 562” then
FrontCrew562 = FrontCrew562_File.OpenAsPicture // Uses the Crew Neck Sweat Shirt Picture and adds to window
if FrontCrew562 <> nil then
Canvas5.Refresh //forces the canvas to display the scaled image
end if
end if
end if
end if
end if

Dim Back29M_File as FolderItem
Dim Back996_File as FolderItem
Dim BackCrew562_File as FolderItem
Dim Back29M_LS_File as FolderItem

Back29M_File = GetFolderItem("/Users/tracynolte/Documents/InvoiceProgram/img/Garments/Back29M_S.png", FolderItem.PathTypeShell)
Back996_File = GetFolderItem("/Users/tracynolte/Documents/InvoiceProgram/img/Garments/Back996_S.png", FolderItem.PathTypeShell)
BackCrew562_File = GetFolderItem("/Users/tracynolte/Documents/InvoiceProgram/img/Garments/BackCrew562_S.png", FolderItem.PathTypeShell)
Back29M_LS_File = GetFolderItem("/Users/tracynolte/Documents/InvoiceProgram/img/Garments/Back29M_LS_S.png", Folderitem.PathTypeShell)

if Back29M_File <> nil and me.text = “T-Shirt 29M” then
Back29M_S = Back29M_File.OpenAsPicture //Uses the T-Shirt Picture and adds to window
if Back29M_S <> nil then
canvas6.refresh //forces the canvas to display the scaled image
elseif Back996_File <> nil and me.text =“Hoodie 996” then
Back996_H = Back996_File.OpenAsPicture // Uses the Hoodie Picture and adds to window
if Back996_H <> nil then
Canvas6.Refresh
elseif Back29M_LS_File <> nil and me.text = “Long Sleeve 29LS” then
Back29M_LS = Back29M_LS_File.OpenAsPicture // Uses the LongSleeve Picture and adds to window
if Back29M_LS <> nil then
Canvas6.Refresh
elseif BackCrew562_File <> nil and me.text = “Crew Neck Sweat Shirt 562” then
BackCrew562 = BackCrew562_File.OpenAsPicture // Uses the Crew Neck Sweat Shirt Picture and adds to window
if BackCrew562 <> nil then
Canvas6.Refresh
end if
end if
end if
end if
end if
[/quote]
any ideas.

P.S. im a visual learner so can you show me an example or idea.

If your two code blocks are separated the way I think they are you aren’t drawing anything but the 29M image in the canvas paint event. OpenAsPicture doesn’t send the image to the canvas the way I feel like you think it does.

I’m working on my own stuff so I can’t draw up code for you, but your Combobox (I’d use a popup menu for sizes, like most websites do) should set a property that the Canvas reads to determine which picture to use.

Create a property in the IDE called something like ShirtImage, then on the change event have it change the value of ShirtImage, finally in the Canvas.Paint event select the image using the value of the ShirtImage property.

You’re definitely working too hard.

  1. Either drag all of your pics into your project in which case you can just refer to them by name, or add them to a folder (MyShirts) within your project. That long path name will not work on another users computer anyway.
  2. create a global array of pictures and populate it at app start
    dim shirtPics(25) As picture
    shirtPics(0) = getfolderitem(“MyShirts”).Child(“Back29M_S.png”)
    shirtPics(1) = …etc…
  3. As Tim suggested, now you can just set a variable (ShirtImage) to = the shirt selected in the popup.
  4. Canvas will always be drawing ShirtImage which now = the shirt selected by the user

still can’t get it to work. idk whats up. the example for the global array of pictures helped a lot but still not enough. can someone show me an example of this in use. or if there is an Example project that will help me out ?

This demo shows you how to set it as a property.
I opted to use a PopupMenu because I still think it’s a better solution.


imgselect.zip - 26kb

I used Zelda icons I found lying around my harddisk :stuck_out_tongue:
(they’re included in the zip for convenience, but you probably shouldn’t include them in any commercial projects)

ty again for this. and i did everything like you showed in the example but now I’m getting an NilObjectException [quote] Dim scaleX, scaleY, scale as Double
Dim theLeft, theTop as integer

if FrontPreview <> nil then FrontPreview = Front29M_S //Logo is a property that has been added to the window

//** This is What is NilObjectException
if FrontPreview.width = me.width and FrontPreview.height = me.height then //if pic is smaller than the canvas
//**
theLeft = (me.width - FrontPreview.width)/2 //center the image horizontally
theTop = (me.height - FrontPreview.height)/2 //center the image vertically
g.DrawPicture FrontPreview, theLeft, theTop
else
scaleX = me.width / FrontPreview.width
scaleY = me.height / FrontPreview.height
scale = Min( scaleX, scaleY ) //choose the smaller value
theLeft = (me.width - (FrontPreview.widthscale))/2 //center the image horizontally
theTop = (me.height - (FrontPreview.height
scale))/2 //center the image vertically
g.DrawPicture FrontPreview, theLeft, theTop, (FrontPreview.width * scale), (FrontPreview.height * scale), 0, 0
end if
[/quote]

any ideas why ?
Everything else i copied and just renamed to what i needed it to be.
really need this working.

My bet is you didn’t change the name of the property. Look in the Navigator, I put a property on the Window called SelectedImage. If you’re changing it’s name in Canvas.Paint you need to change it’s actual property name.
or you moved the code out of the Canvas.Paint event.

First thing i did. Its Named FrontPreview =/

Post the proj here, or email me.

Im sending you an email. you will have to fix the Paths for files because we are coding it so only our pcs can use it. but if you an fix it to have it for anyone can then go for it ! I’m just not sure how to fix all that. if you can just fix it and let me know in //Notes how it was fixed that would be great. Thank you

Really appreciate this. Means a lot to me and my job so Thank you again Tim