Relative Window Position Syntax

Moderator: Rathinagiri

Post Reply
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Relative Window Position Syntax

Post by CalScot »

Hi.

I'm trying to load a window that is always at the same position RELATIVE TO the button on the window that calls it -- even if the window that calls it has been dragged to somewhere else on the screen.
I've tried 30 or 40 combinations of things that I thought might work, but anything that doesn't bomb at compile or at runtime just has no effect and the window always comes up at the same, absolute position as in its original definition.

Here's a simple version of one of the things I tried, which should give an idea of what I'm trying to do; to load the new Window at the same column and at 50 pixels below the button whose action calls it:

Function GetWindow3()
nRow := Window2.Button_1.Row +50
nCol := Window2.Button_1.Col
Load Window Window3
Row nRow
Col nCol
Activate Window Window3
Return Nil

I've tried so many versions of the syntax: "Row := nRow", "Window3.Row.Value := nCol", etc., but nothing works. I suspect that the answer is simple, but I just can't think of anything else I haven't tried and can't find anything appropriate in the samples or on any forum. Can anyone help?

Thanks.
CalScot
[u]Moderator Notes[/u] (Pablo César) wrote:Topic moved from Forum en Español.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Relative Window Position Syntax

Post by esgici »

Hi Scott

( By the way is your name really this ? )

I hope that this sample will give you an idea :idea:

Code: Select all

#include "hmg.ch"

PROCEDURE Main()

   DEFINE WINDOW frmMain ;
      AT 0,0 ;
      WIDTH  550 ;
      HEIGHT 300 ;
      TITLE 'Make a child form at relative posisiton' ; 
      MAIN   

      @ 30, 70 BUTTON btnW3 CAPTION "Make W3" ACTION MakeW3()

   END WINDOW // frmMain
   
   CENTER   WINDOW frmMain
   ACTIVATE WINDOW frmMain
   
RETURN // Main()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
   
PROCEDURE MakeW3()

   LOCAL nW3Row := frmMain.Row + ;
                               frmMain.btnW3.Row + 50,;                        
              nW3Col := frmMain.Col + ;
                              frmMain.btnW3.Col
         
   DEFINE WINDOW frmW3 ;
      AT nW3Row, nW3Col ;
      WIDTH  550 ;
      HEIGHT 300 ;
      TITLE 'A child forms at relative posisiton' ; 
      CHILD 

   END WINDOW // frmW3
   
   ACTIVATE WINDOW frmW3
   
RETURN // MakeW3()   

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.
For simplicity I din't use .fmg file.

Values of form coordinate ( Row, Col ) may be

- defined and assigned to public variables BEFORE defining form and used in definition of form.
- will be assigned with

Code: Select all

   frmW3.Row := ...
   frmW3.Col  := ...
AFTER activated form ( fe in the ON INIT procedure ).

Regards
Viva INTERNATIONAL HMG :D
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Relative Window Position Syntax

Post by CalScot »

Hi, esgici.
(Am -I- calling -you- by the right name? My answer to your name question is at the end!)

Yes, your suggestions really helped me a lot! (As always!)

Window3 was already defined (with a lot of data, so I didn't want to redefine it) so I changed my original function to:

Function GetWindow3() && Called by pressing Button_1 in Window2
Load Window Window3
Activate Window Window3
Return Nil

then I added a new function:

Function GetWin3Posn() && Called by ON INIT in Window3
nRow := Window2.Button_1.Row +50
nCol := Window2.Button_1.Col
Window3.Row := nRow
Window3.Col := nCol
Return Nil

And it works (even if I get a momentary flying window as Window3 re-positions itself!!!). The problem now is that it sets Window3 at the coordinates on the overall screen rather than relative to Window2, but I guess I'll try using the Window2 coordinates (instead of the Window2 button), which should work. But your advice has moved me far ahead of where I've been all day -- Thank you!!!!!

On Names: I used CalScot because I am a SCOTsman living in CALifornia. My real name is Laurie, but because that's a girl's name in the USA (but a boy's name in the UK), I tend to use something other than my real name on Blogs and Forums. (I am definitely not a girl!!)
Please let me know if I should address you as something other than "esgici".

Whatever our names: Thank you again, very much.
L. (CalScot)
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Relative Window Position Syntax

Post by esgici »

Hello Scotty

First, naming considerations :

And first of first : "Whatever our names", we are friends.

Probably I couldn't ask right my question.

There is two situation :

- using real ( former / legal ) name for he/she self
- using a human name in conversations, chats

"Nickname" concept is one of Internet requirements and everyone have and should have right of select freely a "code name" for he/she self; nobody can oppose this.

Probably, since I'm an old and old fashioned man, not used to talk to people by their "code name"; "hello xyz, goodbye 1234" ... I want feel always I'm talking to people, not robots !

In other hand, everyone also have and should have the right of using any name he/she like, other than given by parents. Moreover this should be a legal right, regulations should allow to change name at least one time in life.

In short, I wondered "there may be a problem, if I address to you as 'Scott' ?)", not "'Scott' is your legal name?"

Now, "Scotty" is better : Beam me up, Scotty ! ( if there isn't any problem your side )

You are rigth, this isn't my legal name nor surname; but I like it, because is a "real" human name.
The problem now is that it sets Window3 at the coordinates on the overall screen rather than relative to Window2,
The rule is simple : Coordinates ( positions values ) of controls are relative to their parent form and coordinates of forms are relative to desktop (because the desktop is parent of all form). This is for ALL form, CHILD, MODAL etc aren't exceptional.

Please note :

Code: Select all

   LOCAL nW3Row := frmMain.Row + ;                   // Row of MAIN form
                               frmMain.btnW3.Row + 50,;   
Before building CHILD form ( of after closed it) if you move main window over desktop and than click "make" button, new form will placed relative to main form.

I'm glad that your problem is solved.

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D
User avatar
CalScot
Posts: 303
Joined: Thu Mar 21, 2013 12:22 am
Location: California

Re: Relative Window Position Syntax

Post by CalScot »

Thanks, esgici.
(I'll keep calling you that unless/until you suggest something you'd prefer!)

I'd be happy to have you call me "Scotty" -- although it is -you- who has beamed -me- up (out of trouble) so many times, I should be calling you Scotty!

I set the coordinates relative to Window2 (rather than to a button on Window2) and it works perfectly now. ("Set the coordinates"? That sounds like being "beamed up" again!)
Before building CHILD form ( of after closed it) if you move main window over desktop and than click "make" button, new form will placed relative to main form.
That is really useful, and will save me a lot of time in the future.

I can't say thank you enough for all of your help.

Regards,
L. (CalScot) "Scotty" -- from all 3 of me!
Post Reply