|
-
Feb 14th, 2003, 07:09 PM
#1
Thread Starter
Lively Member
[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:
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Form_Load()
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:
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Sub FormInit(frmRef As Form)
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.
-
Feb 14th, 2003, 07:51 PM
#2
The picture isn't missing
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  .
-
Feb 14th, 2003, 09:08 PM
#3
Thread Starter
Lively Member
I have
VB Code:
frmRef.Top = 0
frmRef.Left = 0
in the module, but nothing is appearing in the picture box
-
Feb 14th, 2003, 10:31 PM
#4
PowerPoster
Well
Try :
VB Code:
frmRef.Move Picture1.Left, Picture1.Top
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Feb 14th, 2003, 10:48 PM
#5
Thread Starter
Lively Member
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:
If trvSections.SelectedItem.Key = "options" Then
Load frmOptions
...
End if
in frmOptions:
VB Code:
Private Sub Form_Load()
FormInit Me
End Sub
in mdlGeneral:
VB Code:
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Sub FormInit(frmRef As Form)
SetParent frmRef.hWnd, frmMainScreen.pctFormContain.hWnd
'frmRef.Top = 0
'frmRef.Left = 0
frmRef.Move frmMainScreen.pctFormContain.Left, frmMainScreen.pctFormContain.Top
...
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
-
Feb 14th, 2003, 10:50 PM
#6
Thread Starter
Lively Member
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:
frmMainScreen.Label1.Caption = frmMainScreen.pctFormContain.Top
frmMainScreen.Label2.Caption = frmMainScreen.pctFormContain.Left
frmMainScreen.Label3.Caption = frmRef.Top
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.
-
Feb 14th, 2003, 10:53 PM
#7
PowerPoster
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....
-
Feb 14th, 2003, 11:06 PM
#8
Thread Starter
Lively Member
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,
-
Feb 14th, 2003, 11:07 PM
#9
PowerPoster
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....
-
Feb 14th, 2003, 11:10 PM
#10
Thread Starter
Lively Member
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
-
Feb 14th, 2003, 11:12 PM
#11
PowerPoster
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....
-
Feb 14th, 2003, 11:22 PM
#12
Thread Starter
Lively Member
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.
-
Feb 14th, 2003, 11:27 PM
#13
PowerPoster
Well
It may be as easy as this :
When users select form (node) try this
VB Code:
Call FormPicked.Show(Modal, Picture1)
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Feb 14th, 2003, 11:53 PM
#14
Thread Starter
Lively Member
"object can't be used as an owner form for show()"
-
Feb 15th, 2003, 12:30 AM
#15
Thread Starter
Lively Member
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.
-
Feb 15th, 2003, 12:31 AM
#16
Thread Starter
Lively Member
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.
-
Feb 15th, 2003, 04:32 PM
#17
PowerPoster
Well
Glad you finally got it...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Feb 15th, 2003, 04:32 PM
#18
PowerPoster
Well
Glad you finally got it...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Feb 15th, 2003, 05:25 PM
#19
Thread Starter
Lively Member
thanks for your help james.
I read that other post of yours about the calc BTW, did you ever get it working as planned?
-
Feb 15th, 2003, 05:29 PM
#20
PowerPoster
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....
-
Feb 15th, 2003, 09:28 PM
#21
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|