Results 1 to 21 of 21

Thread: [RESOLVED] Forms in a picture box?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93

    [RESOLVED] Forms in a picture box?

    alrighty, here's what want to do.
    On the left of my program, there is a tree view, and when a node is clicked, to the right of the tree, a new form loads.

    Now, originally I was using an MDI form, with the trv in one child form, and then loading the other forms as children as well. This was working fine, but then I saw in another post, when looking for help on something else, a suggestion to use a picturebox to the left of the trv in the same form, and using the following (from here :
    VB Code:
    1. Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    2.  
    3. Private Sub Form_Load()
    4.  
    5. SetParent Frame1.hWnd, Picture2.hWnd

    I changed the code a little, I have a module, and in that mod there is a sub that is called for each form load (except the main one), so I added the code into the module instead of each form:
    VB Code:
    1. Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    2.  
    3. Public Sub FormInit(frmRef As Form)
    4.     SetParent frmRef.hWnd, frmMainScreen.pctFormContain.hWnd

    but whenever I click on a node, not only does nothing load in the picture box, the whole app seems to lose focus as well, any ideas?
    Last edited by thetakerfan; Feb 15th, 2003 at 01:09 AM.

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    it will lose focus as the new loaded window will have the focus. you also need to set the left and top to the relative to the new postion (ie set the top and left to 0) so you can see it
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    I have
    VB Code:
    1. frmRef.Top = 0
    2.     frmRef.Left = 0
    in the module, but nothing is appearing in the picture box

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Try :

    VB Code:
    1. frmRef.Move Picture1.Left, Picture1.Top
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    nope, style nothing. Let me try to be more specific, maybe I forgot to mention something. My main form is called "frmMainScreen", and in that form there is a treeview "trvSections". To the right of the treeview there is a picture box, "pctFormContain." When certain nodes of the treeview are clicked, they load a corresponding form, which should be placed into the picturebox. Here is the pertinent code:
    in frmMainScreen:
    VB Code:
    1. If trvSections.SelectedItem.Key = "options" Then
    2.         Load frmOptions
    3.         ...
    4.    End if

    in frmOptions:
    VB Code:
    1. Private Sub Form_Load()
    2.     FormInit Me
    3. End Sub

    in mdlGeneral:
    VB Code:
    1. Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    2.  
    3. Public Sub FormInit(frmRef As Form)
    4.     SetParent frmRef.hWnd, frmMainScreen.pctFormContain.hWnd
    5.     'frmRef.Top = 0
    6.     'frmRef.Left = 0
    7.     frmRef.Move frmMainScreen.pctFormContain.Left, frmMainScreen.pctFormContain.Top
    8.    ...
    9. End Sub

    However, nothing is appearing in the picturebox. Those are the only details I can think to post, and I don't see anything missing, but maybe it'll help

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    alright, after all that typing, I tried frmRef.Show, and now it does indeed appear in the picturebox, but it is not located anywhere near where it is suppsoed to be.

    I tried putting .top and .left back to 0, still not in the right place

    [edit]I decided to see what the top/eft values where, so I added 4 forms to the main form, and put this inside the FormInit sub:
    VB Code:
    1. frmMainScreen.Label1.Caption = frmMainScreen.pctFormContain.Top
    2. frmMainScreen.Label2.Caption = frmMainScreen.pctFormContain.Left
    3. frmMainScreen.Label3.Caption = frmRef.Top
    4. frmMainScreen.Label4.Caption = frmRef.Left

    The numbers that it gave are 120, 2400, 9300, and 6375 respectively, but the numbers for a different form are completely different.
    Last edited by thetakerfan; Feb 14th, 2003 at 10:58 PM.

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Honestly, I would use MDIForm for this. The only time I have used SetParent was when I wanted to include a seperate program to look as if it were a prt of my app...

    Look here to see what I mean...

    http://www.vbforums.com/showthread.p...light=calc.exe
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    Originally I was using an MDI form, and was perfectly content with it that way, but it sort of a pain getting the layout correct that way since I couldn't put the forms next to each other and see the spacing and size properties to make sure it looked right. But then I saw this suggestion somewhere, and now I'm hell bent to get it to work! lol. This way also makes it easier for me to make it scrollable.

    If only I could add treeviews to the MDI form,

  9. #9
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    If only I could add treeviews to the MDI form
    Place the treeview inside a Picturebox, which can be added to the MDI Form...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    damn, that got my hopes up, but when I try to put the picture box in the MDI form, I can't change the width.

    I guess I could just make it the size of the whole form and just make it transparent, but thats kind of sloppy...oh well

    [edit]wait, no I can't, becuase then I just run back in to the original problem with the forms being in a picture box...ugh

  11. #11
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Use two pictureboxes.

    One the size of the MDI container. (size the picturebox on the load of the MDIForm).

    The other to hold all other components. (such as another Picturebox with a Treeview inside... )

    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    that isn't working out right, and I don't think I like the idea of all those picture boxes all over the place.

    If noone can figure out how to do it the way I was trying, I'll just go back to the original way of doing it, no biggie I guess. I'll give it some more time, maybe something will dawn on me that I missed, or maybe someone else, otherwise its back to the drawing board.

  13. #13
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    It may be as easy as this :

    When users select form (node) try this

    VB Code:
    1. Call FormPicked.Show(Modal, Picture1)
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    "object can't be used as an owner form for show()"

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    I don't know why, but now the forms are in the right place as far as left/right go, it fits right in the picture box (before it was off to the right), but it starts way down, and the top/left numbers are both huge, so I don't know what is going on.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    ooooooooooooookaaaaaaaaaaaaaaay...I just got the brilliant idea to put setparent AFTER setting top/left to 0, and low and behold, it seems to be working now...duh me, thanks for the all the help and suggestions, I think I can get it all working as planned now.

  17. #17
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Glad you finally got it...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  18. #18
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Glad you finally got it...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    thanks for your help james.

    I read that other post of yours about the calc BTW, did you ever get it working as planned?

  20. #20
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by thetakerfan
    thanks for your help james.

    I read that other post of yours about the calc BTW, did you ever get it working as planned?
    NOPE. Sometimes you gotta let things go. I wound up downloading code for a simple calc and utilize in my app...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    93
    oh, lol

    as long as it gets the job done I guess

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