Does anyone have any example code that will show me how to resize a form's controls when the user resizes the window? I have looked and found some examples but I am not really sure how to incorporate it into FF.
Thanks in advance,
Hi Noble,
I have created a sub called ResizeControlOfForm() that I call when I have to resize a control (and only one) on a FORM; this SUB resize this control proportionally to the size of the FORM; this SUB is useful only to resize the main control of the FORM (ListView, Picture, etc ...).
To use it you have :
1. To complete the message handler for the %WM_SIZE message of the FORM; see below the example Function FORM1_WM_SIZE ()
2. To replace the second parameter with the handle of the control to resize when you call the sub ResizeControlOfForm().
Important notice: this SUB ResizeControlOfForm() uses TAG and TAG2 to save and restore the latest width and height of the FORM; before using this SUB be sure that you don't use TAG and TAG2 for other purpose in your program.
'--------------------------------------------------------------------------------
Function FORM1_WM_SIZE ( _
hWndForm As Dword, _ ' handle of Form
fwSizeType As Long, _ ' type of resizing request
nWidth As Long, _ ' new width of client area
nHeight As Long _ ' new height of client area
) As Long
' If the window has not been been minimized.
If fwSizeType <> %SIZE_MINIMIZED Then
' The second parameter is the handle of the control to resize
ResizeControlOfForm(hWndForm, HWND_FORM1_LISTVIEW1, nWidth, nHeight)
End If ' If fwSizeType <> %SIZE_MINIMIZED Then
End Function
Sub ResizeControlOfForm( ByVal hWndForm As Dword, _
ByVal hWndControl As Dword, _
ByVal nWidth As Long , _
ByVal nHeight As Long _
)
Local lFormLastWidth As Long
Local lFormLastHeight As Long
Local nChangeWidth As Long
Local nChangeHeight As Long
Local rc As Rect
Local nControlWidth As Long
Local nControlHeight As Long
' use TAG And TAG2 instead of using global variables
' to retrieve the previous width and height of the FORM
lFormLastWidth = Val(FF_Control_GetTag(hWndForm))
lFormLastHeight = Val(FF_Control_GetTag2(hWndForm))
' if the previous width or height are null => Exit
If (lFormLastWidth = 0) Or (lFormLastHeight = 0) Then
GoTo ExitOut
End If
' only if the FORM has been resized
If (lFormLastWidth <> nWidth) Or (lFormLastHeight <> nHeight) Then
' compute the size of the CONTROL
GetWindowRect hWndControl, rc
nControlWidth = rc.nRight - rc.nLeft
nControlHeight = rc.nBottom - rc.nTop
' compute the change for the width and height of the FORM
nChangeWidth = nWidth - lFormLastWidth
nChangeHeight = nHeight - lFormLastHeight
' resize the CONTROL itself proportionally to the new size of the FORM
SetWindowPos hWndControl, 0, 0, 0, _
nControlWidth + nChangeWidth, _
nControlHeight + nChangeHeight, _
%SWP_NOMOVE Or %SWP_NOZORDER
End If
ExitOut:
' use TAG And TAG2 instead of using global variables
' to save the current width and height of the FORM
FF_Control_SetTag (hWndForm, Format$(nWidth))
FF_Control_SetTag2(hWndForm, Format$(nHeight))
End Sub
That is interesting. I suppose one would do this for each control on the form if they wanted all the controls to resize as the window was resized?
When there is only one CONTROL to be resize proportionally to the size of the whole FORM, it's easy: the position of the control doesn't change, just its size.
When there are more controls to be resized I think that it is another story; in that case not only you have to change the size of the control but you have also to move the control to a new position, due to the reduce size of the other controls on the same FORM! should not be a easy task to achieve.
Jean-Pierre
Hello Nobel,
I am working on just what you need. I am to the point it would be useful, but not actually finished yet. How urgent is your need?
Best regards,
David Kenny