Results 1 to 7 of 7

Thread: How to capture the background to STDPicture

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    113

    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

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    113

    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:
    1. Private Sub Command1_Click()
    2.  Picture2.PaintPicture Picture1.Picture, 0, 0, , , _
    3.  ScaleX(Command1.Left, Picture1.ScaleMode, vbPixels), ScaleY(Command1.Top, Picture1.ScaleMode, vbPixels), Command1.Width, Command1.Height, vbSrcCopy
    4.  Picture2.Refresh
    5.  Command1.Picture = Picture2.Image
    6. End Sub
    7. Private Sub Form_Load()
    8.  Picture2.ScaleMode = vbPixels
    9.  Picture2.AutoRedraw = True
    10.  Picture2.Width = Command1.Width
    11.  Picture2.Height = Command1.Height
    12. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    113

    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

  5. #5
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: How to capture the background to STDPicture


  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    113

    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    113

    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
  •  



Click Here to Expand Forum to Full Width