Transparent Picture
|
|
Thread rating:  |
Ivar - 29 Jun 2004 08:47 GMT Hi all.
I need a little bit of help, I can't seem to find what I'm looking for. The background of the form is a tiled picture filling the whole form. I would like to be able to put a picturebox on the form where one colour of the picture in the box is transparent, so that the tiles on the form show through it. I think I'm looking for a sub that has two args, (picBox As PictureBox, Colour as Long). I've found a few examples of making forms transparent, or making pictures appear transparent as long as the container form is one colour. But making a part of a PictureBox Transparent on a multicoloured form is escaping me.
Thanks for any Ideas.
Ivar
J French - 29 Jun 2004 09:49 GMT >Hi all. > [quoted text clipped - 8 lines] >appear transparent as long as the container form is one colour. But making a >part of a PictureBox Transparent on a multicoloured form is escaping me. I think you would be better off using a UserControl rather than a Picturebox
Try this: 1) Open a new Project 2) Project/Add UserControl - New UserControl 3) Put a Commandbutton on the UserControl 4) Paste in this :- Option Explicit
Private Sub Command1_Click() AutoRedraw = True BackColor = vbWhite BackStyle = 0 ' Transparent ' --- ScaleMode = vbPixels FillColor = vbBlue FillStyle = vbFSSolid ' --- CurrentX = 0 CurrentY = 0 Circle (20, 20), 20, vbBlue ' --- MaskPicture = UserControl.Image MaskColor = vbWhite ' --- CurrentX = 20 CurrentY = 20 Print "Hullo" End Sub
5) Close UserControl ( Ctl F4 ) 6) Place UserControl on Form 7) Run and click Commandbutton
Basically the UserControl is very similar to a Picturebox - but it also has a MaskPicture and MaskColor
HTH
Ivar - 29 Jun 2004 11:41 GMT Hi J.
Yep, I agree I would be better off using a UserControl, I tried your example and all works well. Trouble is - this is a modification of someone else's app, and if you knew how much work would be involved in converting all those PictureBoxes (plural) to user controls I'm sure you would have sympathy for me Is there an easier way to do it with the existing controls These PictureBoxes are in 6 or 7 control arrays and have a small Rectangular bmp picture of an oval image (75 of them). each corner of the bmp is Grey, I would like the grey to be transparent and still be able to use the HDC property of the PictureBox. Although this app is not a game, it works like a card game, with the PictureBoxes being dragged around the screen.
Thanks a lot
Ivar
> Try this: > 1) Open a new Project [quoted text clipped - 35 lines] > > HTH Mike Williams - 29 Jun 2004 12:01 GMT > These PictureBoxes are in 6 or 7 control arrays and have a small > Rectangular bmp picture of an oval image (75 of them). each corner > of the bmp is Grey, I would like the grey to be transparent and still > be able to use the HDC property of the PictureBox. Although this > app is not a game, it works like a card game, with the PictureBoxes > being dragged around the screen. Why exactly do you need to use the hDC property of the Picture Box? What else are you doing? Please explain *exactly* what it is your app needs to do (in as much detail as possible) and we'll come up with a solution for you.
Mike
Ivar - 29 Jun 2004 12:29 GMT OK, here we go! This app has been made very graphical, and apart from the little grey triangles in the pictureboxes all looks very good. The events in the pictureboxes used is MouseDown, MouseMove and MouseUp. The App is part of the front end of a database, and records are updated etc depending on where a picturebox is dragged from and dropped to, that bit all works well. But: The pictures in the PictureBoxes Change alot, and they fade from one picture to the other using the AlphaBlend API They also resize themselves according to the screen resolution, and resize the picture (stored in resource file) using StretchBlt. They also use the line method, vbDstInvert in the PaintPicture Method and the print method so that text appears over the top of the picture.
It's one of those little annoying things, this whole app works and looks very good dispite my extensive mods and additions, just those little grey triangles that are clearly visible just slightly spoils what in every other way is a good peice of work.
I was hoping for that magic little sub that could make those little grey triangles dissapear.
Thanks for your help
Ivar
> Why exactly do you need to use the hDC property of the Picture Box? What > else are you doing? Please explain *exactly* what it is your app needs to do > (in as much detail as possible) and we'll come up with a solution for you. > > Mike J French - 29 Jun 2004 13:06 GMT >Hi J. > [quoted text clipped - 9 lines] >property of the PictureBox. Although this app is not a game, it works like a >card game, with the PictureBoxes being dragged around the screen. A UserControl does have a hDC - only you have to expose it.
I suggest that you back up thoroughly - move the App to another HD or directory - preferably machine - and then slaughter it
Best to do it in the morning after a couple of over strength cups of coffee.
From reading further down the thread, it is obvious that the App was mis-designed in the first place - by somebody who did not know about UserControls - or it was originally written in VB4 or lower
If you back up carefully then you can do no damage
Also, you can make a UserControl look and behave just like a Picturebox - so after a few tests, the initial functional conversion will only require a text editor on the raw .FRM files.
Do a few gentle tests to make sure you understand what is going on (eg: create a fake Picturebox)
Then go for 'slash and burn' - it is the only way to break out of a 'corner'
Ivar - 29 Jun 2004 13:37 GMT Hi J & Mike
The old app was writtn in VB6 3 or 4 years ago, and was in severe need of an update. I never met the person who wrote it, but he knew what he was doing, but just had no interest in little grey triangles. (each to their own).
So here's my plan.
Go Home, sit at home PC with Coffee, fags and the door shut Design a user control that will internally duplicate the functions that happens to the pictureboxes in the program. Backup original program, put new usercontrol in place of pictureboxes and name it with the old picturebox names then run app. End result will be either: People will stop asking me about those little grey triangles, app will look better, I will be a hero and the sun will shine. OR Lump in throat, smoke even more fags, get depressed, post more to the thread, reminisce about old career not being that bad after all.
Thanks everyone
Ivar
> A UserControl does have a hDC - only you have to expose it. > [quoted text clipped - 21 lines] > Then go for 'slash and burn' > - it is the only way to break out of a 'corner' J French - 29 Jun 2004 14:25 GMT <snip>
>So here's my plan. > >Go Home, sit at home PC with Coffee, fags and the door shut >Design a user control that will internally duplicate the functions that >happens to the pictureboxes in the program. <snip>
Mostly I advocate caution when coding
- in this case (subject to rigorous backing up) ... just hack it (obviously after a prototype exercize)
Best of luck - it is unpleasant, but occasionally necessary
Feedback would be interesting - others years from now might stumble on this thread
Randy Day - 29 Jun 2004 22:36 GMT > Hi all. > [quoted text clipped - 8 lines] > appear transparent as long as the container form is one colour. But making a > part of a PictureBox Transparent on a multicoloured form is escaping me. Look into the BitBlt API call and Masking: http://www.vbaccelerator.com/home/VB/Tips/Mask_Images/article.asp
> Thanks for any Ideas. > > Ivar Ivar - 30 Jun 2004 14:34 GMT Cheers Randy, but not what I was looking for. The link shows how to make some of a picture "Appear" to be invisible, but not actually be invisible. not good if anything is behind the picbox or the form has images. I did the job, using a user control to act very similar to a PictureBox, and all works and looks good. Trouble is - I didn't get paid for that bit of the prog update, I had to do it at home for love. And there was erindoors telling me there are more important things in life than little grey triangles. What does she know.
Thanks all
Ivar
> Look into the BitBlt API call and Masking: > http://www.vbaccelerator.com/home/VB/Tips/Mask_Images/article.asp Michael B. Johnson - 30 Jun 2004 16:28 GMT - snip -
>all works and looks good. Trouble is - I didn't get paid for that bit of the >prog update, I had to do it at home for love. And there was erindoors >telling me there are more important things in life than little grey >triangles. What does she know. A job well done - you deserve your feeling of satisfaction! Relish it, your work might just be re-used in the future - things often have a way of growing beyond their original scope. And now you've added yet another tool to your arsenal of techniques. :-)
Who is erindoors anyway, and will she ever come understand the value of fine work?
>Thanks all > >Ivar > >> Look into the BitBlt API call and Masking: >> http://www.vbaccelerator.com/home/VB/Tips/Mask_Images/article.asp _______________________ Michael B. Johnson
|
|
|