Simple drop and Paint an image file

Hi all,

I shared a project with a small image I have troubles with. (link: far bottom)

The project main window comes from a far lager one (the window comes…). It is very simple (the part to check). Build with Xojo 2016r1.1 (for the testing), you only have to load it, drop the image (or any other small image) into the window mid part (a Canvas).

What I want to know is if the droped image appears on screen or not.

If not, what am I doing wrong ?


PS: when I uncomment the last line in Canvas’ DropObject, I was able to see both images (the one from Graphics, more or less centered) and the one from Backdrop (a premiere), then when I uncomment it back, I never was able to saw it.

PPS: I quit Xojo when I notices that it does not works… I cleared teh cache, I shutdown / boot back… no change.

I even created a brand new user with the same non result (no image drawn on screen !)

I boot on Recovery partition, fired Disk Utils, check the hard disk: no reported failure (nothing bad reported)
My boot SSD have 33MB of free space, there is so many months i stopped to connect an external hard disk when I want to try to develop with Xojo…

small project

You’re not redrawing after updating the picture.

Try this, after dropping the file and no picture shows up… resize the window.

The fix, at the end of DropObject add


I didn’t look at your project, but my guess is that the line you commented out was setting the backdrop. That would force a refresh on the canvas, which would in turn cause the Paint event to draw the image. That would explain why you see 2 copies when you set the backdrop and no copies when you don’t. The solution, as Will suggests, is to Invalidate the canvas instead of setting the backdrop.


Will: I try…

Tim: you are right, but I wanted to g.drawPicture it in the Paint event. I used the Backdrop trick to be sure the drop process worked.

I try the Invalidate trick and:

the trick works… half works !

I set the Canvas to await a Tab to get the Focus ring and then, the image was drawn.

Nota: in the original project, I put the default window above that window, release the mouse, then move that window to show the other one and nothing was paint. I also used (OS X) the cmd-`keyboard shortcut (go to the next window) instead of moving the front window to let the offending one be visible and nothing.

At last, in the Paint Event, I have:

g.DrawPicture Logo_Pict,100,100

that is - of course - Nil at run time, and I do not have a crash. That line is a debug line. My real wway to draw the Logo_Pict (window Property) is in a If Logo_Pict = Nil Then Block to avoid troubles at run time (since Logo_Pict is Nil then).

This is a real mystery and I need Sherlock Holmes for help :frowning: or ;-:slight_smile:

I had a trouble and wanted to test something, so I put my


Line in Line 0 of the Paint Event.

Then, run, set the Focus to the Canvas (press the Tab key), then drop the small image I shared with the project and get it directly.

Still strange to me.

This is like if the Canvas does not have the focus, it will never display the image when one is dropped.

Nota: the two lines below do nothing (not the awaited crash) even if they are the only lines of the Paint Event:
Dim Toto as Picture

g.DrawPicture Toto,100,100

No, no container control.

At last, part of the below (extract from the [LOCAL] documentation) is wrong:

I do not used the areas parameter.

Strange. Invalidate should work, even on Mac where the display is buffered. Calling Refresh instead of Invalidate would fix it, but shouldn’t be required.

[quote=274632:@Emile Schwarz]At last, part of the below (extract from the [LOCAL] documentation) is wrong:

The area needs to be redrawn, such as when it has been covered by another window and then uncovered. Use the g parameter for all drawing.The areas parameter contains the areas of the Canvas that need redrawing. If areas is empty then the entire Canvas needs to be redrawn.
What’s wrong about that? It seems accurate.

Thanks Tim.

The application does not know about the overlaping windows… and what the documentation says about that.

So, either the application (here) or the documentation is wrong.

Also, this demonstrates that I (tried to) read the documentation. :slight_smile:

What makes you think the application doesn’t know about the overlapping windows? Have you inspected the areas parameter and found it to be wrong? Or are you saying that because the canvas isn’t redrawn every time a window overlaps? On a buffered system like Mac or the newer Windows versions, it doesn’t need to be redrawn every time that happens (although it may be, at the discretion of the OS).

The documentation you quoted doesn’t say that it will be redrawn every time, just that when it is, the areas parameter will give you information about what needs to be drawn. Of course, most people simply draw the entire canvas every time anyway. But if performance is an issue, the parameter is there so you can avoid drawing stuff that you don’t need to.

Hi Tim:

Did I made a wrong assumption ? Reading your post (thank you), it seems so.

I tried to clear everything (the Xojo folder in Applications, the other Xojo folders in Library, etc.), then download the 2015r1 dmg, power off the OS X laptop.
Boot, some minutes after, the laptop, install Xojo 2015r1 from the fresh download dmg.
I had a lot of troubles re-installing my license (one of them was an error dialog telling me that Xojo has encountered an error while trying to load itself…).

Now, I build the stand alone from my project (the larger one) and still get strange results.
As an example, the first drag and drop leads to nothing (the image is not displayed), the second one displays the Focus around the Canvas and displays that image, etc.

If I call for help, that is because I really need it. This è§(è{«‘‘Ú® (voodoo job ?) makes me crazy. I even boot on an external hard disk with a fresh installed El Capitan, install Xojo 2015r1 (from the fresh download), in standard Retina mode (I didn’t even took the time to customize that boot disk), load the large project / the demo project, ran them and fall into the same trap (remamber that I added a new user and made tests there too).

Beside a Virus (when no one talks about such beast on OS X) or Black Voodoo, I do not understand why things goes that way. *

This is why I shared the compiled application with the project file: one can find what I do not see / noticed.

Nota: Because I also have troubles with the simple project (one window extract from the large project), when compiled for Windows and run on a Windows 10 laptop, AND, running Xojo 2016r1 (I do not installed previously Xojo 2016r1.1 ) and it behave the same, I decided to use drastic measures I wrote above.

  • I had some “remission” days lately: on two or three occasions, the features I add worked fine on the first attempt. I was really happy. But, some things goes wrong lately (like my printings who only print page headers / footers and strange data in between), the Recents (files) code that start to crash at application IDE quit time… and this.

Don’t know what to say, Emile. Putting me.Invalidate in DropObject immediately following Logo_Pict = LogoPict causes the image to immediately appear on Windows 7. I do not have access to a system similar to yours to test it on, but it should be working. I have no idea why it is not.

That is what I was awaiting.

Me too :frowning:

Thank you for trying to help.

News from my larger project (where I fall into that trap):

I printed its code * to pdf an it is 926 pages long…

  • I had to do that using the current Xojo (2016r1.1) because 2015r1 crashed after I clicked in the Print button. I will issue the report in some minutes.

The installed Xojo 2015r1 have been downloaded yesterday or so (less than a week ago) and then installed from a fresh dmg. (I trashed all Xoj files/folders I found in Library before that fresh install.

Hi Tim,

I used Refresh and the project started to work in every condition (drop from the Finder while the application window is frontmost, Finder frontmost and application window, etc.).

The concerned code is:

Dim LogoFI As FolderItem
Dim LogoPict As Picture

// a. Get a local FolderITem reference
If Obj.FolderItemAvailable Then
// Works on a local variable
LogoFI = Obj.FolderItem

End If

// b. Load the image in a local reference
LogoPict = Picture.Open(LogoFI)
If LogoPict = Nil Then
// Stop here
End If

// c. Deals with the Picture Property
// Logo_Pict = New Picture(LogoPict.Width,LogoPict.Height)

// d. Ask the Canvas to Refresh

If Logo_Pict <> Nil Then // Draw the image g.DrawPicture Logo_Pict,0,0 End If

Logo_Pict is a window property.

Why Invalidate does not works as expected is beyond my understanding.