IcomHF
May 2nd, 2001, 08:44 AM
I'm stumped. How can I do a borderless and tansparent control that also responds to both left and right mouse click? I have a bitmap for my form, and I don't want to see the control. I've tried many things, but have never been able to get it all together.
Also, any ideas on how to limit the shape of a control to round when the control needs to also be a bitmap? I can't seem to get rid of the square background. Trying to specify a mask color only produces a gray background that is still square.
Many Thanks!
shree
May 2nd, 2001, 09:13 AM
In your form,
place a picturebox and set its borderstyle to None.
Set the autoredraw of both the form and the picturebox to True.
Set the scalemode of both the picturebox and the form to pixel.
Now, enter the following code:
private Declare Function CreateEllipticRgn Lib "gdi32" (byval X1 as Long, byval Y1 as Long, byval X2 as Long, byval Y2 as Long) as Long
private Declare Function SetWindowRgn Lib "user32" (byval hWnd as Long, byval hRgn as Long, byval bRedraw as Boolean) as Long
private Declare Function BitBlt Lib "gdi32" (byval hDestDC as Long, byval x as Long, byval y as Long, byval nWidth as Long, byval nHeight as Long, byval hSrcDC as Long, byval xSrc as Long, byval ySrc as Long, byval dwRop as Long) as Long
private Sub Command1_Click()
Call BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Form1.hDC, Picture1.Left, Picture1.Top, vbSrcCopy)
Call SetWindowRgn(Picture1.hWnd, CreateEllipticRgn(0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight), true)
Picture1.Refresh
End Sub
What you have got is a round control, that doesn't show up, but responds to all events of the picturebox.
Blt-ing the background on the picturebox gives it a transparent effect.
SetWindowRgn can be used to shape any control or form (anything having a hWnd) to any shape (as long as we can create a region of that shape)
John G Duffy
May 2nd, 2001, 09:57 AM
Go to Freevbcode.com and search for this item
"Use a Bitmap to Create a Skinnable Irregular-Shaped Form". it shows a good example of "Skinning" a form.
John G
PrimeraTech
June 13th, 2002, 04:23 PM
I have used a product called TYPICAL_FormShaper. It allows you to make a form or a control any shape you wish with a couple of lines of code. I'd recommend it highly.
www.typicalsoftware.com