Jump to content

Resizing issue


Recommended Posts

I am trying to create a GUI with two listviews side-by-side. I want this GUI to be resizable and both of these controls to resize with the GUI, but keep an fixed distance on all sides, including keeping a set distance between them. The $GUI_DOCKLEFT/TOP/BOTTOM/RIGHT stuff all works fine, but on the inside of the GUI I can't figure out how to keep them from separating.

Please see these attached images.

Here is my code, which is just the example for GuiCtrlCreateListView modified to have to of them side-by-side.

#include <GUIConstants.au3>

GUICreate("listview items", 230, 250, 100,200,$WS_SIZEBOX,$WS_EX_ACCEPTFILES)
;~ GUISetBkColor (0x00E0FFFF) ; will change background color

$button1 = GUICtrlCreateButton ("Left Value", 35, 170, 50, 20)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKLEFT+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)

$button2 = GUICtrlCreateButton ("Right Value",145, 170, 50, 20)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKRIGHT+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)

$listview1 = GUICtrlCreateListView ("col1  |col2|col3  ",10,10,100,150);,$LVS_SORTDESCENDING)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)  ; to allow drag and dropping
$item11=GUICtrlCreateListViewItem("item2|col22|col23",$listview1)
$item12=GUICtrlCreateListViewItem("item1|col12|col13",$listview1)
$item13=GUICtrlCreateListViewItem("item3|col32|col33",$listview1)

$listview2 = GUICtrlCreateListView ("col1  |col2|col3  ",120,10,100,150);,$LVS_SORTDESCENDING)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)  ; to allow drag and dropping
$item21=GUICtrlCreateListViewItem("item2|col22|col23",$listview2)
$item22=GUICtrlCreateListViewItem("item1|col12|col13",$listview2)
$item23=GUICtrlCreateListViewItem("item3|col32|col33",$listview2)

$input1=GUICtrlCreateInput("Drag an item into this box", 20, 200, 150, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)  ; to allow drag and dropping

GUISetState()

Do
  $msg = GUIGetMsg ()
     
   Select
      Case $msg = $button1
         MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview1)),2)
      Case $msg = $button2
         MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview2)),2)
      Case $msg = $listview1
         MsgBox(0,"listview2", "clicked="& GUICtrlGetState($listview1),2)
      Case $msg = $listview2
         MsgBox(0,"listview2", "clicked="& GUICtrlGetState($listview2),2)
   EndSelect
Until $msg = $GUI_EVENT_CLOSE

Which style or ExStyle am I missing? I've tried adding $GUI_DOCKVCENTER to the GuiSetResizing calls, which has no effect.

I thought of using a "Case $msg = $GUI_EVENT_RESIZED" and then doing a GuiCtrlSetPos() for each of the listviews to fix the view, but I don't see a way to get the current (new) size of a GUI in the help to calculate what the new position and width should be.

I'm sure the answer is obvious, but it's got me stumped. I've always said the best way to hide something from me is to put it in plain site, and I'm sure this is no different. If someone can just give me a hint as to which style/ExStyle I'm missing, or how to get the new GUI size, I would appreciate it.

Thanks in advance!

cw

My UDFs: ExitCodes

Link to comment
Share on other sites

I am trying to create a GUI with two listviews side-by-side. I want this GUI to be resizable and both of these controls to resize with the GUI, but keep an fixed distance on all sides, including keeping a set distance between them. The $GUI_DOCKLEFT/TOP/BOTTOM/RIGHT stuff all works fine, but on the inside of the GUI I can't figure out how to keep them from separating.

Please see these attached images.

Here is my code, which is just the example for GuiCtrlCreateListView modified to have to of them side-by-side.

#include <GUIConstants.au3>

GUICreate("listview items", 230, 250, 100,200,$WS_SIZEBOX,$WS_EX_ACCEPTFILES)
;~ GUISetBkColor (0x00E0FFFF); will change background color

$button1 = GUICtrlCreateButton ("Left Value", 35, 170, 50, 20)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKLEFT+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)

$button2 = GUICtrlCreateButton ("Right Value",145, 170, 50, 20)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKRIGHT+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)

$listview1 = GUICtrlCreateListView ("col1  |col2|col3  ",10,10,100,150);,$LVS_SORTDESCENDING)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlSetState(-1,$GUI_ACCEPTFILES) ; to allow drag and dropping
$item11=GUICtrlCreateListViewItem("item2|col22|col23",$listview1)
$item12=GUICtrlCreateListViewItem("item1|col12|col13",$listview1)
$item13=GUICtrlCreateListViewItem("item3|col32|col33",$listview1)

$listview2 = GUICtrlCreateListView ("col1  |col2|col3  ",120,10,100,150);,$LVS_SORTDESCENDING)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlSetState(-1,$GUI_ACCEPTFILES) ; to allow drag and dropping
$item21=GUICtrlCreateListViewItem("item2|col22|col23",$listview2)
$item22=GUICtrlCreateListViewItem("item1|col12|col13",$listview2)
$item23=GUICtrlCreateListViewItem("item3|col32|col33",$listview2)

$input1=GUICtrlCreateInput("Drag an item into this box", 20, 200, 150, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)
GUICtrlSetState(-1,$GUI_ACCEPTFILES) ; to allow drag and dropping

GUISetState()

Do
  $msg = GUIGetMsg ()
     
   Select
      Case $msg = $button1
         MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview1)),2)
      Case $msg = $button2
         MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview2)),2)
      Case $msg = $listview1
         MsgBox(0,"listview2", "clicked="& GUICtrlGetState($listview1),2)
      Case $msg = $listview2
         MsgBox(0,"listview2", "clicked="& GUICtrlGetState($listview2),2)
   EndSelect
Until $msg = $GUI_EVENT_CLOSE

Which style or ExStyle am I missing? I've tried adding $GUI_DOCKVCENTER to the GuiSetResizing calls, which has no effect.

I thought of using a "Case $msg = $GUI_EVENT_RESIZED" and then doing a GuiCtrlSetPos() for each of the listviews to fix the view, but I don't see a way to get the current (new) size of a GUI in the help to calculate what the new position and width should be.

I'm sure the answer is obvious, but it's got me stumped. I've always said the best way to hide something from me is to put it in plain site, and I'm sure this is no different. If someone can just give me a hint as to which style/ExStyle I'm missing, or how to get the new GUI size, I would appreciate it.

Thanks in advance!

cw

definetly the "Case $msg = $GUI_EVENT_RESIZED" is the only way ControlGetPos($gui,"",$controlid)

$gui return by GUICreate

$controlid return by GUICreateListview

WinGetPos($gui,"") will return the size of the entire window.

You have to compulte and set the new size with GUICtrlSetSize($controlid,...) :P

Link to comment
Share on other sites

definetly the "Case $msg = $GUI_EVENT_RESIZED" is the only way ControlGetPos($gui,"",$controlid)

$gui return by GUICreate

$controlid return by GUICreateListview

WinGetPos($gui,"") will return the size of the entire window.

You have to compulte and set the new size with GUICtrlSetSize($controlid,...) :lmao:

I had a feeling that was the way to go, and I forgot about WinGetPos. :P

Thanks jpm!

My UDFs: ExitCodes

Link to comment
Share on other sites

Adding this to the Select block worked for me:

Case $msg = $GUI_EVENT_RESIZED
            $w = WinGetClientSize($WinTitle)
            $w = $w[0]; Window's width
            GUICtrlSetPos($listview1, 10, 10, $w/2-15)
            GUICtrlSetPos($listview2, $w/2+5, 10, $w/2-15)

It is a little strange, however, as while you're dragging the window the auto-resizing takes place and when you release the controls adjust. Is there a way to run through this manual resize code while the window is being dragged?

*EDIT* I tried the line below, but it still doesn't execute until the mouse button is released.

Case $GUI_EVENT_PRIMARYDOWN and ($oldwidth <> $winwidth)
Edited by c0deWorm

My UDFs: ExitCodes

Link to comment
Share on other sites

Here is my current code:

#include <GUIConstants.au3>

$WinTitle = "listview items test"

GUICreate($WinTitle, 230, 250, 100,200,$WS_SIZEBOX,$WS_EX_ACCEPTFILES)
;~ GUISetBkColor (0x00E0FFFF) ; will change background color

$button1 = GUICtrlCreateButton ("Left Value", 35, 170, 50, 20)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKLEFT+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)

$button2 = GUICtrlCreateButton ("Right Value",145, 170, 50, 20)
GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM+$GUI_DOCKRIGHT+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)

$listview1 = GUICtrlCreateListView ("col1  |col2|col3  ",10,10,100,150);,$LVS_SORTDESCENDING)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)  ; to allow drag and dropping
$left11=GUICtrlCreateListViewItem("left2|col22|col23",$listview1)
$left12=GUICtrlCreateListViewItem("left1|col12|col13",$listview1)
$left13=GUICtrlCreateListViewItem("left3|col32|col33",$listview1)

$listview2 = GUICtrlCreateListView ("col1  |col2|col3  ",120,10,100,150);,$LVS_SORTDESCENDING)
GUICtrlSetResizing(-1, $GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)  ; to allow drag and dropping
$right21=GUICtrlCreateListViewItem("right2|col22|col23",$listview2)
$right22=GUICtrlCreateListViewItem("right1|col12|col13",$listview2)
$right23=GUICtrlCreateListViewItem("right3|col32|col33",$listview2)

$input1=GUICtrlCreateInput("Drag an item into this box", 20, 200, 150, 25)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT+$GUI_DOCKWIDTH)
GUICtrlSetState(-1,$GUI_ACCEPTFILES)  ; to allow drag and dropping

GUISetState()

Do
    $msg = GUIGetMsg ()

    Select
        Case $msg = $button1
            MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview1)),2)
        Case $msg = $button2
            MsgBox(0,"listview item",GUICtrlRead(GUICtrlRead($listview2)),2)
        Case $msg = $listview1
            MsgBox(0,"listview2", "clicked="& GUICtrlGetState($listview1),2)
        Case $msg = $listview2
            MsgBox(0,"listview2", "clicked="& GUICtrlGetState($listview2),2)
        Case $msg = $GUI_EVENT_RESIZED
            $winwidth = WinGetClientSize($WinTitle)
            $winwidth = $winwidth[0]; Window's width
            GUICtrlSetPos($listview1, 10, 10, $winwidth/2-15)
            GUICtrlSetPos($listview2, $winwidth/2+5, 10, $winwidth/2-15)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE

My UDFs: ExitCodes

Link to comment
Share on other sites

Adding this to the Select block worked for me:

Case $msg = $GUI_EVENT_RESIZED
            $w = WinGetClientSize($WinTitle)
            $w = $w[0]; Window's width
            GUICtrlSetPos($listview1, 10, 10, $w/2-15)
            GUICtrlSetPos($listview2, $w/2+5, 10, $w/2-15)

It is a little strange, however, as while you're dragging the window the auto-resizing takes place and when you release the controls adjust. Is there a way to run through this manual resize code while the window is being dragged?

*EDIT* I tried the line below, but it still doesn't execute until the mouse button is released.

Case $GUI_EVENT_PRIMARYDOWN and ($oldwidth <> $winwidth)
use $GUI_DOCKno =0 no resizing will be done by default. Perhaps $GUI_DOCKALL is better.

$GUI_EVENT_RESIZED mean fire only when resizing is done. See Guilbuilder.au3 in Scite perhaps he find a better way to do it.

Edited by jpm
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...