Is there any way I can make only ONE color on my form transparent? I want to make the form invisible but keep any image data I may have on there (like from using .print or .line).
Printable View
Is there any way I can make only ONE color on my form transparent? I want to make the form invisible but keep any image data I may have on there (like from using .print or .line).
There is a method to create a rounded form, for example. This is made with a masked picture that tells which part of the form is visible and which is not. Would this help?
Have a look at this. This example has the masked already loaded in the form.
Try this... I think it is exactly what you want.
Mc Brain if what you posted does this then sorry, it didn't sound like it :p
Not quite. I posted a simpler sample. An here is an even simpler way.Quote:
Originally Posted by penagate
Oops, forgot to mention this needs to be on Windows 98. I'll take a look at the examples now...
Nove, true transparency is only supported on Windows 2000 and higher.
You can still do funny shaped forms in Win 98 but no translucency effects.
Ok, then is there a way to make a certain color of a picture box transparent?
The code I posted works on W98. However, it is neither true transparency, nor translucent. Maybe it's not what you need.Quote:
Originally Posted by penagate
Mc Brain when I run the 2nd project you posted I see white dots to the right of the black text. I have some other regioning code which doesn't do that.
Basically just call RegionFromImage from the Form_Initialize sub. Unlike your example it does need a picture box with an image in it. Also you need to pass the background (transparent) colour.Code:Public Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public Function RegionFromImage(fRgnForm As Form, picBackground As PictureBox, ByVal lBackColor As Long) As Long
Dim hRegion As Long
Dim lpicHeight As Long
Dim lpicWidth As Long
Dim lRow As Long
Dim lCol As Long
Dim lStart As Long
Dim hTempRegion As Long
Dim lResult As Long
hRegion = CreateRectRgn(0, 0, 0, 0)
With picBackground
lpicHeight = .Height / Screen.TwipsPerPixelY
lpicWidth = .Width / Screen.TwipsPerPixelX
For lRow = 0 To lpicHeight - 1
lCol = 0
Do While lCol < lpicWidth
Do While (lCol < lpicWidth) And _
(GetPixel(.hDC, lCol, lRow) = lBackColor)
lCol = lCol + 1
Loop
If lCol < lpicWidth Then
lStart = lCol
Do While (lCol < lpicWidth) And _
(GetPixel(.hDC, lCol, lRow) <> lBackColor)
lCol = lCol + 1
Loop
If lCol > lpicWidth Then lCol = lpicWidth
hTempRegion = CreateRectRgn(lStart, lRow, lCol, lRow + 1)
lResult = CombineRgn(hRegion, hRegion, hTempRegion, RGN_OR)
Call DeleteObject(hTempRegion)
End If
Loop
Next
End With
RegionFromImage = hRegion
SetWindowRgn fRgnForm.hwnd, hRegion, True
End Function
Nove if you are printing text/lines to the form, to use this code just print them to a picture box instead, and pass the background colour of the picture box to the funciton.
I think you see those dots because the image is aliased. The image should get an anti-aliased. That's an example I downloaded some time ago.Quote:
Originally Posted by penagate
That makes sense, they must be almost white but not quite.
If so then I think you example is better than mine because it doesn't require a picturebox.
Penagate, where/how do I use your code?
Here's a sample with penagate's code. However... it seems to be a little slow (with large images). Unfortunately... it won't make it as transparent as almost all men would want. ;) (You'll understand when you see the sample).Quote:
Originally Posted by Nove
I clicked the command button, but nothing happened. Was something supposed to?
Some pixels of the image should be turned into "transparent" (and see the light blue form's backcolor. Bear in mind, that the model's top is not perfectly white but has a lot of shades.
I replaced the picture with just a white background, I couldn't really see any difference with the picture there. Works though, now maybe I can implement the two...
transLUCENT effects require win 2000 (well, they don't, but 2000 has api support for them)
transPARENT is an easier beast and can be done in 98
What's the difference?
Hey, I need to make the form transparent in color, but actually tangible, as in I can see what's underneath it but when i click on that area I click on the form, not the junk underneath. Possible?
No. That's a translucent form. And can only be achieve with W2K Up (I don't know if it can be done in NT either).Quote:
Originally Posted by Nove
McBrain that is a terrible example :eek2:
nice picture though :p
And yeah, maybe this whole transparency/translucency thing need clarifying. Translucency (semi-opacity) and full transparency can both be achieved by alpha blending. Full transparency can also be achieved by regioning which is what the examples in this thread are doing. Basically it just consists of telling Windows where to cut the edges of the form out. Alpha blending on the other hand makes either the whole form or pixels of a certain colour on the form, semi-opaque (a bit like Mc Brain's picture :p )
The API needed for alpha-blending is only available in Win 2K+. The APIs used for regioning however are available in Win 95+.
Sorry. He was saying he wanted to do it a picture, and I thought it should be with a photo.... and don't have much photos for an example. :blush:Quote:
Originally Posted by penagate
When you cant control what image is going to be used so you can make sure its anti-aliased you can always seperate the colors down to their RGB components and check them to see if the difference between them all is minute, sounds like a lot of checking but its not too bad and helps a lot on some images.
Since regions is the subject here and is spawned from the very same beginnings as my project, i have a question...
After deciding the 'BlueScreening' method wasnt quite what i needed I ended up drawing my images manually (just semi-complex shapes) by creating regions, and using FillRgn and FrameRgn. Worked good, however I did it on a UserControl. Inside that usercontrol i have another nested usercontrol which plays animations. my problem? when i play the animation in the nested control, my entire control with the painted region is invalidated and disappears leaving only the nested animation control showing. Its not clipping...so...what am i missing? :ehh:
If i lock the window update, then the animation isnt seen, so i need to lock everything but the animation...
I dont know...im tired and irritated heh. :sick: