PDA

Click to See Complete Forum and Search --> : Transparency Issues with a User Control


TheLGM
Jun 17th, 2002, 02:06 AM
I recently created a user control, which basically contains 4 small image fields. I made the background of the control transparent.

The problem is this. Even though the control background is transparent, the areas inside the image boxes (which contain icons with transparency) is the background color of the control (white) This is what it looks like.
http://thelgm.bemanimn.com/problem1.gif

I played around with some settings, and made the control windowless. That seemed to work as you can see here
http://thelgm.bemanimn.com/problem2.gif

Now, normally I would rejoice, but I found an issue with that. This control is inside a scrolling picture box. When I scroll, the CPU gets maxed out -- so badly that the redraw rate stars to falter. Since I only used one control (anticipating there being 200+ in this scrolling picture box) and got these results, I would hate to see what happens when I get the picture box loaded up. Is there some way I can make the control look like the 2nd picture, but somehow forego the big processor requirement to draw it?

Jotaf98
Jun 17th, 2002, 05:43 PM
Well, you could do something like this... make the control REALLY windowless (so it doesn't show up at all), and do something like this:



Private Sub Picture1_Paint()
YourCustomControl.PaintStuff
End Sub



Now, when that function is called, use VB's PaintPicture function to draw the image to YourCustomControl.Parent (the parent control - Picture1), on the control's coordinates. Or use BitBlt, which is a lot faster than PaintPicture. That's the fastest method I can think of, but you will always have to use some code in the Paint event of the picturebox :)

Janus
Jun 17th, 2002, 08:09 PM
Window transparency does NOT work well in any situation, except for top-level windows. Even in that situation, it's often slow. Especially when scrolling. I suggest 'faking' the transparency by either not using usercontrols (which is a good idea anyway, as each one uses additional GDI, User, and system resources) and painting to the parent picturebox, or virtual-scrolling - use a fixed number of them in the picturebox and change their appearance to fake scrolling.

TheLGM
Jun 17th, 2002, 09:21 PM
Thanks for the advice. I fear I won't be able to make use of it though. The big reason for this is because I need to remove the arrows at any time, if I paint them, removing a single arrow will be pretty tough.

that's why I created the user control. I wanted an actual object I could add and remove, and most importantly one that has custom properties. I guess my only alternative is to just write a whole bunch of code to simulate those 4 arrows found in my control (and the extra properties)

Better than nothing, eh?

Again, thanks for the advice. :)

Jotaf98
Jun 19th, 2002, 06:13 PM
Heh read my first reply, you can still use the control and the 4 corners thingy ;)