I need a controller to be transparent and a container. Nothing more.
The controller is transparent as start, but how do I also add property hDC to it? In that way calling it like "usercontrol1.hCd x, y"
Anyone?
Printable View
I need a controller to be transparent and a container. Nothing more.
The controller is transparent as start, but how do I also add property hDC to it? In that way calling it like "usercontrol1.hCd x, y"
Anyone?
Not really sure what you mean - but if you want to make a usercontrol to be a container - just set the ControlContainer property to be true.
To expose the hDC property - just add the following to the control:
VB Code:
Public Property Get hDc() As Long hDc = UserControl.hDc End Property
Does this help?
Yes that's it. But I already managed to figure that out when using the property wizard.
However, It didnt work as I planed. I need to do bltbit on the form or a picturebox. but want their background to be transparent. I used the form and put it to transparent (borderstyle=0) and added hDc, but the image didnt get printed on the form. it probably got printed, but the form is transparent. wacked!
there must be som way. because i want to move the image as It is transparent as well.
With GDI it is possible I think, but I have no idea how to do it. Have anyone here coded with GDI?
Have you tried TransparentBlt to copy the image??
Isn't TransparentBlt an function found on the internet? I don't think it's an actual API, in which case, Planet Source Code or Google can help.
Phreak
No No - its a real function
Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
Oh my god. I searched for ages long ago and had to come up with my own! Then I got told there was one on the internet...
/me slaps myself..
Phreak
Okey, I have no idea what you mean. Anyway....
I want to use the forma png as it is anti-aliased. I have printed a transparent anti-aliased PNG file on a PictureBox. However as the PictureBox isnt transparent the image will not be transparent on the form.
I could print it on the form directly, but then I cant use the properties on the PictureBox so I can move it with the mouse.
I have included the file here. Have a look and see what im trying to do. Press the color buttons and look what I mean with with the picturebox layer is blocking the image.
Anyone know how to use the GDI and print PNG files, that would be better. I've seen a quite messy applikation doing so.
I can't use the project because I don't have a license for the SetPNGImage
Try this set the png picture to a picture box using the setpngimage function then copy the picture from the picturebox to the form using the transparentblt function [defined above]: - use it like this:
BOOL TransparentBlt(
HDC hdcDest, // handle to destination DC
int nXOriginDest, // x-coord of destination upper-left corner
int nYOriginDest, // y-coord of destination upper-left corner
int nWidthDest, // width of destination rectangle
int hHeightDest, // height of destination rectangle
HDC hdcSrc, // handle to source DC
int nXOriginSrc, // x-coord of source upper-left corner
int nYOriginSrc, // y-coord of source upper-left corner
int nWidthSrc, // width of source rectangle
int nHeightSrc, // height of source rectangle
UINT crTransparent // color to make transparent
);
If you were referring to to the PNGlib then just register it in the command prompt. SetPNGImage is just a function to load the image.
to register it type:
"regsvr32 pnglib.dll"
to unregister it type:
"regsvr32 pnglib.dll /u"
I guess you already know that. Anyway, it wont work until you register the dll.
Try it, then you will know what im trying to do.
This is a very rough version - I think it will give you some pointers of what to do. I have moved the textbox and the picturebox into a usercontrol that is transparent.
Does this help
I couldnt load the ocx and ctl. it wasnt loaded automatic, so I tried browsing to it manually but it didnt showup as a file. I then tried draging it into visual basic but got a error message "it is not a registered controller".
Can you try unziping the file into a new folder and open the project from this new folder.
I have tried it here everything worked.
Try it again - if it still doesn't work I will repost.
Rob
Ok, got it to load. But how can I make this work?? I dont undestand the point with it? Hmm, explain or better show me what you mean.
You could move it around with the mouse using the form. The form has the same basic drawing properties of the PictureBox, aswell as the same Functions (MouseDown/Up, etc..)Quote:
Originally Posted by haruki
Phreak
The controller needs hDc to function. It doesnt have that, how do I add that to the customized controller?
So I can test print on it.
Quote:
Originally Posted by THEROB
This will expose the hDC - just paste it into the usercontrol. Since the usercontrol has been set to transparent it should still be transparent when the PNG file is copied to it.
Ok, I've added that then refresh and autodraw that is needed. The projects starts and the images doesnt show. Have you tested it?
Anyway, I think it is because the background is transparent, than the print will be that too. As the print is a part of the bakground, not a layer.
I can't think of any proper way to do what you want. When you copy the image to a hdc - the transparent bits of the picture become the background of the control.
The only way I can think of is to set the image of the picture box to be the background - then copy over the png file - you will need to do this every time there is any movement - this will be very slow.
Since the only parts of the Png file that are transparent is the border - you could just cut out the border
I would suggest changing the design.
R
I've seen other use png files with movement, transparent and anti-aliased.
Here's one code I found doing so, but its messy. So I dont really get any information from it as it has few comments if any at all.