 |
|
 |
I've tried this code but the CopyFromScreen seems to copy the image behinde the form not the control, pls correct me if I'am wrong or if I'm using it wrong!
|
|
|
|
 |
|
 |
Great Works. But it works only for text not for Picture. Does it do transparent pic or i did any wrong?
|
|
|
|
 |
|
 |
The title is deceiving.. and the code is full of issues (see previous commenters). If you really want a transparent control, override it's CreateParams property and add the WS_EX_LAYERED attribute. Alternately, if you do not need mouse clicks you can use WS_EX_TRANSPARENT. Both methods are Googleable, and both avoid the potential pitfalls many of the other's are warning about.
|
|
|
|
 |
|
 |
Poor discription, and as said in the comments, flicker may appear. More information about the problem should be given. Code itself isn't that bad.
|
|
|
|
 |
|
 |
I didn’t experience any flicker when using this code, and given that the code runs in milliseconds, certainly didn’t find it to be a poor performer, at least for what I was needing it for.
I found it to be a very helpful solution to a particular problem in VB, where the transparency option causes a “hole” in the display.
However, I'm ALWAYS interested in learning new techniques, so could you post some code that shows us how to make a control appear to be transparent, yet doesn't have this apparent flickering problem?
|
|
|
|
 |
|
 |
Hi, when will u come up with a proper solution 4 this issue...?
|
|
|
|
 |
|
 |
Poor performance. Inaccurate description of what was copied - It copies everything, not just what is behind. (Ignores Z-order)
|
|
|
|
 |
|
 |
Got a better solution? I'm always up for learning new things
What kind of performance issue are you concerned with!!
I used this technique to create a "sproinging" effect with a label. When the player won the game, a label containing "You won" appeared to spring forward and backwards in the screen.
All I did was change the font size and then repaint the label copying the background of the control each time. The label grew or contracted as the font size changed.
This visual effect lasts maybe 2-3 seconds, the code is executed 20 times in that 2-3 seconds and I'm not experiencing any flicker.
Other than creating this kind of visual effect, most Forms based programs wouldn't need to call the code as frequently as I did, so I'd hardly classify the code as a performance disaster.
I think the kids that like to throw out the "it's slow code" flames need to actually run the code before commenting, and think about it's application.
modified on Friday, April 17, 2009 1:26 PM
|
|
|
|
 |
|
 |
I never said it was a performance disaster - it does have it's place, but you have be aware that you can't use this code in all situations and that is what your article does. You never explained how and when to use it, so I am making a worst case scenario. This code has been done before over the years and the results have always been lacking.
Test #1: Install a background image in the parent control and then run your control over that.
Test #2: Install a control like a textbox that shows the computer time updating to the tenth of a second (Just so it shows allot of changes) - only it is above your control. Are you capturing the background or are you capturing everything minus your control? Now push it to the background and your control is in front - does the time show correctly or is it choppy?
Test #3: Do Both
Test #4: Make your control movable by changing the location along with the mouse movement. Does the image keep up over the parent background image? (ie... Override OnMove and use Me.Refresh instead of MyBase.OnMove(e)) This is the hardest thing to do with any control. It has to draw as fast as possible.
You also have to remember that the graphics are driven by the cpu and not off-loaded to a video card, so you can't control how your code works on somebody else's computer and their results will be different. Computers are much faster now then just two years ago, but a slow computer will have problems with this code. Anytime you hide a control and reshow it you are inviting flicker. It's easy to be flicker free when the background doesn't change or is a basic color, to show it when it does change is much harder.
modified on Friday, April 17, 2009 7:33 PM
|
|
|
|
 |
|
 |
is a bit off. When you set the BackColor of a control to Transparent, it doesn't cause the control to hide anything. What it does do is tell the control to render it's background using the background properties of its parent container.
Without modification, controls are never transparent. That's why you can't see other controls sitting behind a "transparent" control.
|
|
|
|
 |
|
 |
I did actually point that out in the code comments:
'The control isn't truly transparent, but it appears to be.
|
|
|
|
 |
|
 |
unlistedemail24@gmail.com wrote: 'The control isn't truly transparent, but it appears to be.
Is a very vague description that tells you nothing about the details of what's going on.
|
|
|
|
 |
|
 |
I was desperately searching for a solution... and your article has appeared like a miracle! Thanks!
|
|
|
|
 |
|
 |
Happy to have helped Daniele.
|
|
|
|
 |
|
 |
You should give more explanation about the code, instead of just throwing it out there.
Nothing wrong with the code itself, though.
|
|
|
|
 |
|
 |
Nothing wrong with the code itself, though.
I see one big thing about the code that is a problem. Hiding - Waiting - Grabbing the picture then update - Show - Wait some more. All that takes TIME. When you are painting a control - it has to be done as fast as possible. Hiding and then Showing invites Flicker. Put a picture in the control's parent backimage and run the code - you will see what I mean.
Also; there is no code to keep track of the background changes - that may mean updating every time the control is painted.
In a nutshell - poor performance. This does not mean it does not have it's place, but you have to be very aware of this issue.
|
|
|
|
 |
|
 |
Well, it's better code than i could come up with, so that makes it good for me. I'm not such a good programmer, though, so i guess you're right.
|
|
|
|
 |
|
 |
What kind of performance issue are you concerned with!!
I used this technique to create a "sproinging" effect with a label. When the player won the game, a label containing "You won" appeared to spring forward and backwards in the screen.
All I did was change the font size and then repaint the label copying the background of the control each time. The label grew or contracted as the font size changed.
This visual effect lasts maybe 2-3 seconds, the code is executed 20 times in that 2-3 seconds and I'm not experiencing any flicker.
Other than creating this kind of visual effect, most Forms based programs wouldn't need to call the code as frequently as I did, so I'd hardly classify the code as a performance disaster.
I think the kids that like to throw out the "it's slow code" flames need to actually run the code before commenting, and think about it's application.
modified on Friday, April 17, 2009 1:05 PM
|
|
|
|
 |