Link to home
Start Free TrialLog in
Avatar of Gamemaster328
Gamemaster328

asked on

form inside picture box

how do u put a form inside a picture box?

i used this code

Private Sub Load_Click()
    Form2.Show
End Sub
Avatar of spiritwithin
spiritwithin

A form is a window. A picturebox is a control. A control has to be set into a window. Therefore, a window can not be set into this control.
Another point is, that the mouse does not act in a picturebox as it acts in a form. You can not click something, and drag it - inside of a picturebox, without specialized coding. Which all brings me to the point, that you might mean you want to have a sceenshot of the form, inside of a picturebox ?? That's possible and easy. Cheers.
Avatar of Gamemaster328

ASKER

i really dont need to drag it to a picture box i just need to press buttons.  i dont need to a mouse either.
So in other words, you want the picture box to contain buttons. That's easy, go run Visual Basic and create buttons inside of your picture box, like you would do with a form. You will end up having your buttons in the picturebox. Maybe that's what you need?
I don't know why you want to do it, but here you go:

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Public sub SetFormInsidePBox(byval hWndForm as long, byval hWndPBox as long)
    setparent hwndform, hwndpbox
end sub

You use the above like this:

setforminsidepbox form2.hwnd, form1.picture1

And remember to take it out before unloading form1:

Setparent form2.hwnd, getdesktopwindow
I believe you want a picture in the background? Here's what to do. Make a form and the same size of the picture you have. Then set the properties of the form to:
picture = "your pic"
borderstyle = "None"

here you've got a picture with everything you want in it!
now make a button with the caption "Exit" or whatever and:

Private Sub Command1_Click()
     Unload Me
End Sub

Perfect!
Woa. What webJose provided here is very nice. I tested it without success, anyway, im new to the idea of putting a form into a picturebox. I should not have answered that fast. Sorry to guide you wrongly, Gamemaster. Cheers.
Avatar of Ryan Chong
Instead of set the form's parent to picturebox, try set the form's parent to another form that contain picturebox. Use the Setparent API that webJose provided and it should works.

cheers
ASKER CERTIFIED SOLUTION
Avatar of webJose
webJose

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
add that code to where?
IT WORKS!!! thanks guys i really appreciate this. i was trying to make a code like this for ever! :) thanks!