ON PAINT weird behavior

54 views
Skip to first unread message

Gilbert Vaillancourt

unread,
May 5, 2026, 10:03:24 AM (13 days ago) May 5
to Harbour Minigui
Hi All,

I have an application where a serie of button are defined at the bottom of the form. 
When sizing the form I want the button to stay on the bottom of the form.
To acheive this I'm using the ON PAINT clause of the form.
If I enlarge the form, everything is ok. Buttons stays on bottom of the form whether I enlarge from the top or the bottom of the form.
But if I reduce the form, the buttons disapear from the bottom and don't show back unless I re-enlarge the form.

Here is my test code:

#include "MiniGui.ch"

//-----------------------------------------------------------------------------

#define RGB_DKGRAY    {64,64,64}
#define RGB_LTGRAY    {112,128,144}

//-----------------------------------------------------------------------------

static scAppPath

//-----------------------------------------------------------------------------

function Main ()
local nRow := 700
local nCol := 500
local nHeight := 300
local nWidth  := 1250

SET CENTURY ON
SET DELETED ON
SET BROWSESYNC ON
SET SOFTSEEK OFF
SET LANGUAGE TO ENGLISH
SET DATE FORMAT "dd/mm/yyyy"
SET EPOCH TO Year(Date())

scAppPath := GetStartUpFolder()

define window oWndLaunch             ;
       at nRow, nCol                 ;
       width nWidth height nHeight  ;
       title "HMG Launcher"          ;
       backcolor RGB_DKGRAY          ;
       main nominimize nomaximize    ;
       on init {|| Initialize()}     ;
       on paint {|| UpdtForm()}      ;
       on interactiveclose {|| Quit()}

@ (ThisWindow.Height -70), (ThisWindow.Width -120) buttonex oBtnExit ;
       caption "Exit"                                   ;
       width 100 height 25                              ;
       action {|| Quit()}                               ;
       font "ARIAL" size 10                             ;
       bold                                             ;
       fontcolor {255,255,255}                          ;
       backcolor {  0,  0,  0}                          ;
       gradientfill {{1, {  0,  0,  0}, {192,192,192}}} ;
       noxpstyle notransparent

@ (ThisWindow.Height -70), (ThisWindow.Width -230) buttonex oBtnHelp ;
       caption "Help"                                   ;
       width 100 height 25                              ;
       action {|| MsgInfo("Help")}                      ;
       font "ARIAL" size 10                             ;
       bold                                             ;
       fontcolor {255,255,255}                          ;
       backcolor {  0,  0,  0}                          ;
       gradientfill {{1, {  0,  0,  0}, {192,192,192}}} ;
       noxpstyle notransparent

@ (ThisWindow.Height -70), (ThisWindow.Width -340) buttonex oBtnAbout ;
       caption "About"                                  ;
       width 100 height 25                              ;
       action {|| MsgInfo("About")}                     ;
       font "ARIAL" size 10                             ;
       bold                                             ;
       fontcolor {255,255,255}                          ;
       backcolor {  0,  0,  0}                          ;
       gradientfill {{1, {  0,  0,  0}, {192,192,192}}} ;
       noxpstyle notransparent

@ (ThisWindow.Height -70), (ThisWindow.Width -450) buttonex oBtnSetup ;
       caption "Setup"                                  ;
       width 100 height 25                              ;
       action {|| MsgInfo("Setup")}                     ;
       font "ARIAL" size 10                             ;
       bold                                             ;
       fontcolor {255,255,255}                          ;
       backcolor {  0,  0,  0}                          ;
       gradientfill {{1, {  0,  0,  0}, {192,192,192}}} ;
       noxpstyle notransparent

   _DefineHotKey("oWndLaunch", MOD_ALT, VK_X, {|| Quit()})

end window

if nRow == 0 .and. nCol == 0
   oWndLaunch.Center()
endif
oWndLaunch.Activate()

Return (NIL)

//-----------------------------------------------------------------------------

function Initialize ()

Return (NIL)

//-----------------------------------------------------------------------------

function Quit ()

ReleaseAllWindows()

Return (NIL)

//-----------------------------------------------------------------------------

function UpdtForm ()

oWndLaunch.oBtnExit.Row  := (ThisWindow.Height -70)
oWndLaunch.oBtnHelp.Row  := (ThisWindow.Height -70)
oWndLaunch.oBtnAbout.Row := (ThisWindow.Height -70)
oWndLaunch.oBtnSetup.Row := (ThisWindow.Height -70)

Return (NIL)

// ------------------------------------------------------------------------------------

Looks like the ON PAINT clause codeblock is called when enlarging but not when reducing. Am I wrong ?

Regard
Gilbert Vaillancourt






Grigory Filatov

unread,
May 5, 2026, 11:17:23 AM (13 days ago) May 5
to Harbour Minigui
Hi Gilbert,

Thank you for your sample.

You have 2 options to solve this problem:

1) use ON SIZE event for your needs. It is a prefereable and working way.

2) use helper timer to force window repainting. This workaround is shown in the updated code below.

#include "MiniGui.ch"

//-----------------------------------------------------------------------------

#define RGB_DKGRAY    {64,64,64}
#define RGB_LTGRAY    {112,128,144}

//-----------------------------------------------------------------------------

static scAppPath
static lRedraw := .f.

//-----------------------------------------------------------------------------

function Main ()
local nRow := 700
local nCol := 500
local nHeight := 300
local nWidth  := 1250

SET CENTURY ON
SET DELETED ON
SET BROWSESYNC ON
SET SOFTSEEK OFF
SET LANGUAGE TO ENGLISH
SET DATE FORMAT "dd/mm/yyyy"
SET EPOCH TO Year(Date())

scAppPath := GetStartUpFolder()

define window oWndLaunch             ;
       at nRow, nCol                 ;
       width nWidth height nHeight   ;
       title "HMG Launcher"          ;
       backcolor RGB_DKGRAY          ;
       main nominimize nomaximize    ;
       on init {|| Initialize()}     ;
       on paint {|| UpdtForm()}      ;
       on size lRedraw := .t.        ;
   define timer nul
       action refreshwin(thiswindow.handle)
       interval 50
   end timer


end window

if nRow == 0 .and. nCol == 0
   oWndLaunch.Center()
endif
oWndLaunch.Activate()

Return (NIL)

//-----------------------------------------------------------------------------

function Initialize ()

Return (NIL)

//-----------------------------------------------------------------------------

function Quit ()

ReleaseAllWindows()

Return (NIL)

//-----------------------------------------------------------------------------

function UpdtForm ()

oWndLaunch.oBtnExit.Row  := (ThisWindow.Height -70)
oWndLaunch.oBtnHelp.Row  := (ThisWindow.Height -70)
oWndLaunch.oBtnAbout.Row := (ThisWindow.Height -70)
oWndLaunch.oBtnSetup.Row := (ThisWindow.Height -70)

Return (NIL)


function refreshwin (nHandle)

if lRedraw
   RedrawWindow( nHandle )
   lRedraw := .f.
endif

Return (NIL)

Hope this is helpful.

Regards,
Grigory

Spencer Redfield

unread,
May 5, 2026, 11:24:25 AM (13 days ago) May 5
to Gilbert Vaillancourt, Harbour Minigui
Hi Gilbert,

Here you can use:

OnSize Event
Occurs when a Window is sized

 

Syntax: OnSize <ActionProcedure>




define window oWndLaunch ;
at nRow,eight nHeight ;

title "HMG Launcher"          ;
backcolor RGB_DKGRAY         ;
main nominimize nomaximize  ;
on init {|| Initialize()}     ;
on paint {|| UpdtForm()}      ;
ON SIZE UpdtForm() ;
on interactiveclose {|| Quit()}


Hope this helps.
Spencer

--
Visit our website on https://www.hmgextended.com/ or https://www.hmgextended.org/
---
You received this message because you are subscribed to the Google Groups "Harbour Minigui" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minigui-foru...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/minigui-forum/dfef1949-2875-4f58-b10f-0f79738f0851n%40googlegroups.com.

Gilbert Vaillancourt

unread,
May 5, 2026, 12:35:55 PM (13 days ago) May 5
to Harbour Minigui
Thanks guys for the hints,

1) use ON SIZE event for your needs. It is a prefereable and working way.
I used that method in the first place. Yes it works but there is an esthetic problem where the buttons will move up in the form while the form is being enlarge and then reposition 
at the bottom of the form when mouse is release. That's why I tried using ON PAINT instead. It gave better results at least when enlarging the form.

2) use helper timer to force window repainting. This workaround is shown in the updated code below.
I tried this solution and it works well. At least I don't loose the buttons anymore. 
But using Spencer's suggestion has the same effect with less code. I did'nt try this method at first, 'cause I did'nt thought it could work...

Thanks to both of you. It did help. 

Regards
Gilbert Vaillancourt
Reply all
Reply to author
Forward
0 new messages