Jump to content

How to calculate the height needed for the scrollbar UDF


 Share

Recommended Posts

With reference to 

and the UDF used is 

I am trying to create a scrollable tab area in a GUI window, exactly like in the quoted thread. In my application, however, the UI controls are added in a modular manner via included scripts. The GUI would look like this.

**************************************************
| ---------------------------------------------- |
| |                                            | |
| |                                            | |
| |  Controls from module1.au3                 | |
| |                                            | |
| |                                            | |
| ---------------------------------------------- |
|                                                |
| ---------------------------------------------- |
| |                                            | |
| |                                            | |
| |  Controls from module2.au3                 | |
| |                                            | |
| |                                            | |
| ---------------------------------------------- |
|                                                |
|    So on so forth                              |
|                                                |
**************************************************

This application will be deployed for use in current and future projects, configured to contain different modules (some of which may be common) for individual projects' requirements. However, this configuration is done by modifying the includes code, so the final GUI from the compiled .exe is fixed and will not change during runtime as per requirement.

It is not feasible to calculate the required height for individual versions of the application and hardcode it everytime. Is there a way to automatically detect how long the scrollbar needs to be? Here is a sample code (can't provide the actual code due to security reasons):

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#include "GUIScrollbars_Ex.au3"

$Form1 = GUICreate("Form1", 800, 600, -1, -1, $GUI_SS_DEFAULT_GUI)
$Tab1 = GUICtrlCreateTab(0, 0, 800, 600)

$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")

GUICtrlCreateTabItem("")

GUISetState(@SW_SHOW)

$child1 = GUICreate("Child1", 640, 480, 80, 70, $WS_POPUP, $WS_EX_MDICHILD, $Form1)

$top = 10
For $i = 1 To 100
  GUICtrlCreateInput("Input" & $i, 10, $top, 620, 22)
  $top += 32
Next

GUISetState(@SW_SHOW)

$scrollHeight = 1000
_GUIScrollBars_Generate($child1, 0, $scrollHeight)

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
WEnd

The current $scrollHeight of 1,000 defined above is not long enough to display all 100 input fields created. How do I display all of them, with a 10px vertical margin? Calculating it manually, $scrollHeight needs to be about [100 x (22 + 10) + 10] = 3,210. But how can I automate this calculation in code? Like I said, different versions of the application used by different projects will have different UI controls implemented, which will not change dynamically during runtime.

Link to comment
Share on other sites

  • Moderators

thegreatjedi,

If all of the controls are created within the UDF and always run from top to bottom than something like this might be useful:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#include "GUIScrollbars_Ex.au3"

$Form1 = GUICreate("Form1", 800, 600, -1, -1, $GUI_SS_DEFAULT_GUI)
$Tab1 = GUICtrlCreateTab(0, 0, 800, 600)

$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")

GUICtrlCreateTabItem("")

GUISetState(@SW_SHOW)

$child1 = GUICreate("Child1", 640, 480, 80, 70, $WS_POPUP, $WS_EX_MDICHILD, $Form1)

; Create a dummy control
$cStart_CID = GUICtrlCreateDummy()
;ConsoleWrite($cStart_CID & @CRLF)

; Start of modular code
$top = 10
For $i = 1 To 100
  $cCID = GUICtrlCreateInput("Input" & $i, 10, $top, 620, 22)
  ;ConsoleWrite($cCID & @CRLF)
  $top += 32
Next
; End fof modular code

; Create another dummy
$cEnd_CID = GUICtrlCreateDummy()
;ConsoleWrite($cEnd_CID & @CRLF)

GUISetState(@SW_SHOW)

; Get positions of first and last controls created by the modular code
$aPos_Start = WinGetPos(GUICtrlGetHandle($cStart_CID + 1))
$aPos_End = WinGetPos(GUICtrlGetHandle($cEnd_CID - 1))

; Calculate differnece in y coord between first and last and then add a couple of individual heights
$iDifferenceInHeight = $aPos_End[1] - $aPos_Start[1] + (2 * $aPos_Start[3])
;ConsoleWrite($iDifferenceInHeight & @CRLF)

; Now use this as the scroll height
$scrollHeight = $iDifferenceInHeight ; 1000
_GUIScrollBars_Generate($child1, 0, $scrollHeight)

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
WEnd

A warning - this trick will only work if the first and last controls created by the modular code are the top and bottom controls.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...