Jeffeffo
Jeffeffo

Reputation: 1

Is there a reason why BringToFront() and SendToBack() functions for pictureBoxes are not working on my VB forms program?

I'm coding a UI using pictureboxes as my buttons and menus. They function well, however when my popup menu pops up, it pops up behind my UI buttons. Alongside this, the transparency from both the pictureboxes don't seem to function, as when visual basic sees a pixel as transparent, it shows the background and not the picturebox behind it, like this:

screen shot of bad transparency

After this occured, I attempted using the built in functions for pictureboxes, BringToFront() and SendToBack(), which made no changes whatsoever.

Upvotes: 0

Views: 63

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 416121

I'm coding a UI using pictureboxes as my buttons and menus.

This is a bad idea that will hurt performance, memory use, and polish for the app.

the transparency from both the pictureboxes don't seem to function

This is a long-standing "feature" of Windows Forms (and MFC before that). It's a performance optimization to make this possible from before transparency was commonplace and easy/quick. Instead, it's not true transparency, but "fakes it" by capturing an image of what is behind the control when it's first drawn, and then also drawing your transparent image over top of this captured bitmap. The new combined image is then used as the true background for the control.

This works for basic things, but causes problems on more dynamic layouts. "But I don't want that". Then you can implement your own transparency; otherwise that's just too bad. There is a small work-around using the Invalidate() method to force repaints, but it's not something you can do, for example, as an animation is running or as the user is dragging a control, and because the event loop process order is non-deterministic it's unreliable for multiple layers of "transparent" items.

Upvotes: 2

Related Questions