Click to See Complete Forum and Search --> : making form appear in a particular position
christophe
Jan 12th, 2000, 02:13 AM
I have a form with a command button which makes another form pop up:
Private Sub Command1_Click()
Form2.Show
End Sub
Does anyone know the code I can use so that form2 will be aligned with the bottom right hand corner of form1? ie: Form2 will appear on top of form1, with the bottom right corner coordinates exactly on top of that of form1?
Thanks for any help!
netSurfer
Jan 12th, 2000, 02:25 AM
Well, there's a couple ways to do this. You can set the location of where the form appears by setting it's location to manual and then manually placing it where you want it to appear. You could also figure it out using the values in the Left, Top, Hieght and Width properties of the 2 forms. Hope it helps.
form2.left = form1.left + form1.width
form2.top = form1.top + form1.height
That should give you the bottom right hand corner
------------------
Boothman
There is a war out there and it is about who controls the information, it's all about the information.
Thomas Nielsen
Jan 12th, 2000, 02:33 AM
To make form2 appear exactly on top op form1
form2.show
form2.Left = form1.left
form2.top = form1.left
to make form2 appear in front of form1
form2.show
form2.left = form1.left
To make form2 apear at the bottom right cornor of form1
form2.show
form2.left=form1.left + form1.width
form2.top = form1.top + form1.height
--
This should give you a pretty good idea of how to assign a position to a form
Thomas
christophe
Jan 12th, 2000, 02:56 AM
Okay, perhaps I didn't make myself completely clear. I want Form2 to appear on TOP of form 1: The bottom right corner should be aligned with the bottom right corner of Form1, and it should be on top of form1.
I played around with your code above. The closest I got was:
Private Sub Command1_Click()
Form2.Show
Form2.Left = Form1.Left
Form2.Top = Form1.Left
End Sub
by Thomas. (thanks!)
The above code makes form2 align with the top left corner of form1. I thought I could simply replace 'Left' with 'Right', and I would get what I'm looking for, but I got an error. Does anyone know how to do what I want?
Thanks again!
form2.left = (form1.left + form1.width) - form2.width
form2.top = (form1.top + form1.height) - form2.height)
Sorry about the first answer. Did not quite understand. This should work though.
------------------
Boothman
There is a war out there and it is about who controls the information, it's all about the information.
christophe
Jan 12th, 2000, 03:40 AM
Thanks Boothman, it now works fine.
christophe
Jan 12th, 2000, 05:47 PM
Does anybody know why this happens?
With the code below it works fine:
Private Sub Command1_Click()
form2.Show
form2.left = (form1.left + form1.width) - form2.width
form2.top = (form1.top + form1.height) - form2.height
End Sub
form2 loads in the bottom right corner of form1, as planned.
But I have to have form1 as a mdichild form. If I set form1 as a mdichild form, form2 no longer loads in the same position - it loads somewhere totally different. Does anybody know why and how this can be resolved?
My objective is to make form2 load in the bottom right corner of form1.
In any case, thanks for your help.
Merry VIP
Jan 12th, 2000, 06:28 PM
Make the form2 too a mdichild. That's the easiest way.
Hmm...after thinking a while, I think that's THE ONLY way to get it to right position. There may be a API call (I don't know much at API) that can get the position of MDIform's greyarea's x and y position.
If this is not clear, here's a ASCII pic on what I mean, x and y pos what I mean is marked with small x
-----------------------------------
| | MDIform1 |_|O|X|
-----------------------------------
| File Options Help |
-----------------------------------
| x.............................. |
| ................--------------. |
| ................| | form1 |X|. |
| ................--------------. |
-----------------------------------
Just hope that this is not too confusing :)
COPY THAT ASCII PIC TO CLIPBOARD AND OPEN AT NOTEPAD! Makes it much clearer.
Vesa Piittinen
[This message has been edited by Merry VIP (edited 01-13-2000).]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.