About align center controls on a form

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

jparada
Posts: 430
Joined: Fri Jan 23, 2009 5:18 pm

About align center controls on a form

Post by jparada »

Translated by Google,

I have tried to align the center of a form, some controls, such as frame, buttons, progressbar, etc.. and not have done, am doing something like testing as we do in clipper with columns - len (control) (control for the use of len property width) / n but I was not working. Some guidance on this? Wish to align n number of buttons, not just one, an addition (sorry for two questions in one post), how can I control what I design in a form well suited to any screen resolution .

Thanks

Greetings
Javier

Spanish,

He tratado de alinear al centro de un formulario, algunos controles, como, frame, buttons, progressbar, etc. y no lo he logrado, estoy haciendo pruebas con algo parecido a como lo hacemos en clipper con columnas - len(control) (para el len del control utilizo la propiedad width) / n pero no me ha funcionado. Alguna orientación al respecto?, deseo poder alinear n número de botones, no solo uno, además (perdón por dos preguntas en un solo post), como puedo controlar que lo que yo diseñe en un form se adapte bien a cualquier posible resolución de pantalla.

Gracias

Saludos
Javier
User avatar
Alex Gustow
Posts: 290
Joined: Thu Dec 04, 2008 1:05 pm
Location: Yekaterinburg, Russia
Contact:

Re: About align center controls on a form

Post by Alex Gustow »

Hi, jparada !

It's my (very simple) example - how I can create "auto-zoom" for windows and controls for different user's resolution

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2009 Roberto Lopez <harbourminigui@gmail.com>
 *
 * -=- HMG Controls AutoZoom Demo -=-
 * Copyright 2009 Alex L. Gustow <gustow33 @ mail.ru>
*/

#include "minigui.ch"

*-----------------------
Function Main()

  /* -- early it was simple:

  // my screen resolution - 800 x 600

  define window Win_1 ;
    at 0,0 ;
    width 0.8 * 800 height 0.8 * 600 ;
    title 'My Main Window' ;
    main

    @ 20, 40 button B_1 caption "Button_1"

  end window

  Win_1.Center
  Win_1.Activate

  // and what user see?..
  // it depends of his screen resolution
  // (maybe as I see, maybe bigger, maybe smaller)

  -- */

  // now I want the same design (EXACTLY) with
  // different user's screen resolutions

  Def_Pubs()    // definitions of PUBLICs

  define window Win_1 ;
    at 0,0 ;
    width 0.8 * 800 height 0.8 * 600 ;
    title 'HMG Controls AutoZoom Demo' ;
    main ;
    on init Fun_1()

  end window

  // Win_1.Center    move that to Fun_1()
  Win_1.Activate

Return Nil

*-----------------------
Function Fun_1()
* controls defining (with autozoom)

  Win_1.Width  := int( Win_1.Width  * gu_hk )
  Win_1.Height := int( Win_1.Height * gu_vk )

  Win_1.Center    // move here from Main()

  @ 20, 40 ;
     button B_11 of Win_1 ;
     caption "B_11 (no zoom)" ;

  @ 20 * gu_vk, 500 * gu_hk ;
     button B_21 of Win_1 ;
     caption "B_21 (zoom)" ;

  Win_1.B_21.Width    := int( Win_1.B_21.Width    * gu_hk )
  Win_1.B_21.Height   := int( Win_1.B_21.Height   * gu_vk )
  Win_1.B_21.FontSize := int( Win_1.B_21.FontSize * gu_hk )

Return Nil

*-----------------------
Function Def_Pubs()
* definitions of PUBLICs

  public gu_vk := 1, gu_hk := 1   // horizontal & vertical zoom

  public gu_th := GetTitleHeight(), ;
         gu_bw := GetBorderHeight()

  gu_hk := (0.8 * GetDesktopWidth() ) / (0.8 * 800)
  gu_vk := (0.8 * GetDesktopHeight()) / (0.8 * 600)

  MsgInfo( "Your screen resolution is: " + ;
           ltrim(str( GetDesktopWidth() )) + " * " + ;
           ltrim(str( GetDesktopHeight() )) + CRLF + CRLF + ;
           "Design-time screen resolution is: 800 * 600" + CRLF + CRLF + ;
           "Hor.zoom: gu_hk =" + str(gu_hk, 10, 2) + CRLF + ;
           "Ver.zoom: gu_vk =" + str(gu_vk, 10, 2) )

Return Nil
I use HMG Ext (by Grigory & Co.) - but it works (I think) in "standard" HMG too.

Regards! HMG is great thing! I say "Viva!!!" with other HMG-people! :D
jparada
Posts: 430
Joined: Fri Jan 23, 2009 5:18 pm

Re: About align center controls on a form

Post by jparada »

Translated by Google,

Thanks for responding Gustow Alex, I'll take a look at the code.

Thanks
Greetings

Spanish,

Gracias por responder Alex Gustow, voy a echarle un vistazo al código.

Gracias

Saludos
Javier
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: About align center controls on a form

Post by Rathinagiri »

Fantastic Alex Gustow.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Alex Gustow
Posts: 290
Joined: Thu Dec 04, 2008 1:05 pm
Location: Yekaterinburg, Russia
Contact:

Re: About align center controls on a form

Post by Alex Gustow »

rathinagiri wrote:Fantastic Alex Gustow.
:) "Captain Fantastic"?.. (do you remember that ooold album?)

Rathi, did you test this code? What can you say? I use this way in my apps - it required little more thinking during design time, but give good result (and no "eye pain" when user has high screen resolution - 1200 or more).

(15 minutes later) In other words:
We can "auto-zoom" any windows/controls for best user view (equal as designer view). Only Msg***()-functions windows has no effect (and standard API's windows - like GetFolder() etc.) - they have "system default" size.

BTW, definition of "zoomed" button can be written simplier (without additional operators):

Code: Select all

*-----------------------
Function Fun_1()
* controls defining (with autozoom)

  Win_1.Width  := int( Win_1.Width  * gu_hk )
  Win_1.Height := int( Win_1.Height * gu_vk )

  Win_1.Center    // move here from Main()

  @ 20, 40 ;
     button B_11 of Win_1 ;
     caption "B_11 (no zoom)"

  @ 20 * gu_vk, 500 * gu_hk ;
     button B_21 of Win_1 ;
     caption "B_21 (zoom)" ;
     width 100 * gu_hk ;
     height 28 * gu_vk

  // 100 and 28 - default button width and height
  // (see \SOURCE\h_button.prg)

  //Win_1.B_21.Width    := int( Win_1.B_21.Width    * gu_hk )
  //Win_1.B_21.Height   := int( Win_1.B_21.Height   * gu_vk )

  // ?? how I can get default fontsize (for button)?
  // (if I can - we can write it to button definition too)
  Win_1.B_21.FontSize := int( Win_1.B_21.FontSize * gu_hk )

Return Nil
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: About align center controls on a form

Post by Rathinagiri »

Yes, I had tested the code and found it useful. Thanks for sharing. I wish to implement this in one of my projects.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: About align center controls on a form

Post by sudip »

Hi Alex,

Thanks a lot! :)

But, perhaps I have done a mistake so that I am getting following error message.
error.jpg
error.jpg (31.81 KiB) Viewed 5855 times
Can you please tell me where I did wrong :(

With best regards.

Sudip
With best regards,
Sudip
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: About align center controls on a form

Post by esgici »

Hi Sudip

( If Alex will permit and confirm )

simply replace last line of Function Fun_1() :

Code: Select all

Win_1.B_21.FontSize := int( Win_1.B_21.FontSize * gu_hk )


with :

Code: Select all

  nB_21FontSize := GetProperty( "Win_1", "B_21", "FONTSIZE" )
  
  IF HB_ISNIL( nB_21FontSize )
     nB_21FontSize := 8
  ENDIF
    
  SetProperty( "Win_1", "B_21", "FONTSIZE", INT( nB_21FontSize * gu_hk ) )   

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
Alex Gustow
Posts: 290
Joined: Thu Dec 04, 2008 1:05 pm
Location: Yekaterinburg, Russia
Contact:

Re: About align center controls on a form

Post by Alex Gustow »

Hi Sudip & Rathi!
esgici wrote:( If Alex will permit and confirm )
Rathi's fix need (I mean) for HMG "original" only (in HMG Ext. my sample works fine). But why your "default" fontsize is so small?..

Code: Select all

  IF HB_ISNIL( nB_21FontSize )
     nB_21FontSize := 8
  ENDIF
It's for screen resolution about 640*480 (I mean) - in my 800*600 it's 9 or 10 (I don't remember exactly).

Because you guys say "it's good" - I'll worked (a little) and edited sample from SAMPLES\BASIC\IMAGEBROWSE2.
I put it (in RAR) to attach with screenshots of my Desktop (on office computer):
1) 800*600 view;
2) 1024*768 (no zoom; "origin" program) view;
3) 1024*768 (with zoom).
Look at my comments/questions in PRG - maybe we'll solve it together.

Regards
Attachments
Gu_ImageBrowse2.zip
(188.36 KiB) Downloaded 409 times
User avatar
sudip
Posts: 1454
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: About align center controls on a form

Post by sudip »

Hello Alex,

I downloaded the attachment, compiled with Minigui and it ran very fine!!!! :)

Thanks for it!!!

With best regards.

Sudip
With best regards,
Sudip
Post Reply