Jump to content

resize GUI elements


 Share

Recommended Posts

Hi,

I have a simple GUI (one windows), which show a collection of images, like a picture viewer.

Is there a way to make the GUI resizable (this part is ok) so that the pictures (GUICtrlCreatePic) are automaticaly rearrange on a grid in the resized GUI ? Having them reorganized while resizing would also be nice.

Thks

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Link to comment
Share on other sites

Well, I didn't included code because it is pretty simple actually, just a study to see if this gui behavior is possible, to allow me going further.

actually :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Opt("GUIOnEventMode", 1)
;Opt("GUIResizeMode", $GUI_DOCKAUTO)

Global $RootDir = " ***DIR WITH JPEGS*** "
Global $select_menuitem[100]
Global $dir[100]

Global $width = 300
Global $height = 200

$Form1 = GUICreate("test", $width, $width, 200, 200, BitOR($GUI_SS_DEFAULT_GUI,$WS_BORDER,$WS_SIZEBOX,$WS_SYSMENU,$WS_CAPTION))
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close", $Form1)
GUISetState(@SW_SHOW)

Global $pict_width = 50
Global $pict_height = 50
Global $delta_width = 52
Global $delta_height = 52

$files = _FileListToArray($RootDir,"*.jpg",1)
    If @Error = 0 Then
        $top = 2
        $left = 2
        $H_nbr = Int(($width / $delta_width))
        $H = 1
        ConsoleWrite(@CR&"H_nbr : "&$H_nbr)
        for $i=1 to $files[0]
            $dirfile = $RootDir&$files[$i]
            ConsoleWrite(@CR&"indice : "&Round($H_nbr*$H)&"H : "&$H)

            If $i = $H_nbr*$H Then
                $top += $delta_height
                $left = 2
                $H += 1
            EndIf
            GUICtrlCreatePic($dirfile, $left, $top, $pict_width, $pict_height)
            $left += $delta_width
        Next
    EndIf

While 1
    Sleep(100)
WEnd

Func Form1Close()
    Exit
EndFunc

If I resize the window, the pictures just move around. I would have them rearrange to fill the new space accordingly.

Edited by kiboost

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Link to comment
Share on other sites

well, it then resize each single picture so the global ui don't change, but just resize.

At start you have a row of five picts, right ? If I horizontally resize the GUI, I should get more picts in the row. More picts of same size, not same picts of more size :-)

Edited by kiboost

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

Link to comment
Share on other sites

I think you'd need to monitor the size of the GUI as it gets resized and shuffle the positions of your pictures in your code. I am pretty sure that would be the only way to do it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

few question:

Did you want the pics have always the same size?

Did you want the distance between pics always be the same?

Did you want that the windows have scrolls only when the ammount of pics exceed the windows size?

If you have only two pics on the folder. Did the windows size be smaller than usually and unable to be bigger?

i let these questions as a guide

Link to comment
Share on other sites

It can be better and more discursive, but here you got this, maybe you can fix it a little.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <array.au3>
Opt("GUIOnEventMode", 1)
Opt("GUIResizeMode", $GUI_DOCKALL)

Global $RootDir = "G:\Agustin\imagenes para proyectos\"
Global $select_menuitem[100]
Global $dir[100]
global $pic[1]
Global $width = 300
Global $height = 500

$Form1 = GUICreate("test", $width, $width, 200, 200, BitOR($GUI_SS_DEFAULT_GUI, $WS_BORDER, $WS_SIZEBOX, $WS_SYSMENU, $WS_CAPTION))
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close", $Form1)
GUISetState(@SW_SHOW)
_setpics()
GUIRegisterMsg($WM_SIZING, "WM_SIZING")

While 1
    Sleep(100)
WEnd
Func Form1Close()
    Exit
EndFunc   ;==>Form1Close
Func WM_SIZING($hWndGUI, $MsgID, $WParam, $LParam)
        Local $pict_width = 50
        Local $pict_height = 50
        Local $delta_width = 2
        Local $delta_height = 2
        Local $left = 2
        Local $top = 2
    Local $size = WinGetClientSize($Form1)
    For $i = 1 To ubound($pic) - 1
            GUICtrlSetPos($pic[$i], $left, $top, $pict_width, $pict_height)
            If $left + $pict_width*2 >= $size[0] Then
                $top += $delta_height * 2 + $pict_height
                $left = 2
            Else
                $left += $delta_width + $pict_width
            EndIf
        Next
endfunc
Func _setpics()
    $files = _FileListToArray($RootDir, "*.jpg", 1)
    If @error = 0 Then
        redim $pic[$files[0] + 1]
        Local $pict_width = 50
        Local $pict_height = 50
        Local $delta_width = 2
        Local $delta_height = 2
        Local $left = 2
        Local $top = 2
        Local $size = WinGetClientSize($Form1)
        If @error Then
            SetError(1)
            Return False
        EndIf
        For $i = 1 To $files[0]
            $dirfile = $RootDir & $files[$i]
            $pic[$i] = GUICtrlCreatePic($dirfile, $left, $top, $pict_width, $pict_height)
            If $left + $pict_width*2 >= $size[0] Then
                $top += $delta_height * 2 + $pict_height
                $left = 2
            Else
                $left += $delta_width + $pict_width
            EndIf
        Next
    EndIf
EndFunc   ;==>_setpics

PD: still missing the scrolls, i never use and i never saw how it uses

Edited by monoscout999
Link to comment
Share on other sites

Hey monoscout, sorry being late on this one, but your script works like a charm ! Exactly what I need, and not a tons of code and functions, many many thanks for that !!!

Now I have to find how to dragndrop images from my gui to other softwares ...

Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79

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...