|
-
Jan 29th, 2010, 02:41 PM
#1
Thread Starter
Lively Member
How to capture the background to STDPicture
to make a button transparent I want to capture the background image of a form or picturebox (actually the region on which that button is placed) and keep it in a stdpicture varaible then I want to paint this object on the button
I tried the PaintPicture but paintpicture doesnt store its output in a stdpicture
then I thought to use stdpicture render function but still dont know how to copy the source image to destination and set an stdpicture variable to the output of these fucntions
please please help me
-
Jan 30th, 2010, 10:08 AM
#2
Re: How to capture the background to STDPicture
See if this is helpful. This uses a Picture Box (Picture1) as the background
but you could also just assign a picture to the form & substitute Form1
for Picture1 in the code.
Code:
Option Explicit
'Picture1 is the background picture (has a picture)
'Picture2 is the work picture to get the picture
' behind the command button--may set Visible=False
'Command1 is contained in Picture1, though not necessary
Private Sub Command1_Click()
'paint the portion behind the button onto Picture2
Picture2.PaintPicture Picture1.Picture, 0, 0, Command1.Width, Command1.Height, _
Command1.Left, Command1.Top, Command1.Width, Command1.Height, vbSrcCopy
Picture2.Refresh
Command1.Picture = Picture2.Image
End Sub
Private Sub Form_Load()
Me.ScaleMode = vbPixels 'can set all these at design time
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
Picture2.AutoRedraw = True
Picture2.Width = Command1.Width
Picture2.Height = Command1.Height
End Sub
-
Jan 30th, 2010, 12:49 PM
#3
Thread Starter
Lively Member
Re: How to capture the background to STDPicture
Thank you very much
it works, just if one wants to not change the ScaleMode if the form and picture1
can use the code below
vb Code:
Private Sub Command1_Click()
Picture2.PaintPicture Picture1.Picture, 0, 0, , , _
ScaleX(Command1.Left, Picture1.ScaleMode, vbPixels), ScaleY(Command1.Top, Picture1.ScaleMode, vbPixels), Command1.Width, Command1.Height, vbSrcCopy
Picture2.Refresh
Command1.Picture = Picture2.Image
End Sub
Private Sub Form_Load()
Picture2.ScaleMode = vbPixels
Picture2.AutoRedraw = True
Picture2.Width = Command1.Width
Picture2.Height = Command1.Height
End Sub
-
Feb 1st, 2010, 12:07 PM
#4
Thread Starter
Lively Member
Re: How to capture the background to STDPicture
But I noticed I got a problem!!!!!!!!!!
I used this techniq for a user control for a custom button with a transparent background so that everytime I change the background of a from it adopts itself
but since the buttons are a lot
I noticed loading the form takes too much time, then I noticed actually the whole picture of the form is stored in the picturebg property of my user control
so it seems paintpicture doesnt suit
I dont want the whole picture to be stored there just a techniq that cuts the area I need for the button, do you know any method
-
Feb 2nd, 2010, 07:51 AM
#5
Re: How to capture the background to STDPicture
-
Feb 2nd, 2010, 09:20 AM
#6
Thread Starter
Lively Member
Re: How to capture the background to STDPicture
thank you but actually my problem differ, I dont want the transparency that mask color suggests because I think its not smooth and also doesn't support semi-transparency
I have a user control for my buttons, and I use a function which draw a semi-transparent 32 bit bmp on a background, till now my trick was that I made a background by selecting part of the form where the button is supposed to be placed with a graphic software (frireworks) and then use that for the background property of the button, then I could draw any semi-transparent picture on it till I reach a staisfiying result,
since I should test different styles and backgrounds ... providing a background for the button became tedious, so I thought the VB automatically capture part of the background and set the picture needed for background of the button
the above code you mentioned is helpful but now the problem is actually the whole image of the form is stored in the picture property and therefor makes opening the form very slow,
now I am working on the BitBlt function to reach a result (to cut a specific part of the background and store it) but yet its in process
if you have a sugestion please help me, cause it took much time of me
-
Feb 2nd, 2010, 04:03 PM
#7
Thread Starter
Lively Member
Re: How to capture the background to STDPicture
I know there are many people here who are very expert on graphics,
why you dont help me on this simple problem?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|