AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Control Anchoring v4 for resizing windows
Goto page 1, 2, 3 ... 9, 10, 11  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Thu Jul 07, 2005 2:39 pm    Post subject: Control Anchoring v4 for resizing windows Reply with quote

This function defines how controls should be automatically positioned relatively to the new dimensions of a GUI when resized.
Instructions are in the script. The example is also helpful for first time users.

Download Function


Last edited by Titan on Wed Jun 20, 2007 10:56 am; edited 14 times in total
Back to top
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Wed Oct 19, 2005 11:37 pm    Post subject: Reply with quote

* Just updated, it works much better now Smile
Back to top
View user's profile Send private message Visit poster's website
Atomhrt



Joined: 02 Sep 2004
Posts: 128
Location: Sunnyvale

PostPosted: Fri Oct 21, 2005 11:04 pm    Post subject: Reply with quote

Titan wrote:
* Just updated, it works much better now Smile


I use it and another function almost just like it to resize one of my GUI's. It has 29 controls (that are run through the functions) including one listview and four tabs. Works great! Very Happy

One thing that I did because I'm so lazy, is changed the order of the params to the function...
From:
Anchor(Control, Anchors="", x=0, y=0, w=0, h=0)
To:
Anchor(x=0, y=0, w=0, h=0, Control, Anchors="")

This made it a bit easier to create the call for most of the controls since it somewhat follows the format of most of my GUI, Add statements. That is, the x-y-h-w coords first usually followed by a variable name. Using a few find and replace statements with my editor could then do most of the work. Hope that makes sense... Rolling Eyes
_________________
I am he of whom he speaks!


Last edited by Atomhrt on Sat Oct 22, 2005 3:41 pm; edited 1 time in total
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Fri Oct 21, 2005 11:54 pm    Post subject: Reply with quote

Atomhrt wrote:
One thing that I did because I'm so lazy, is changed the order or params to the function...

The open source is there so you can customize it to your needs Wink. Glad you liked it anyway.
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10463

PostPosted: Sat Oct 22, 2005 1:31 am    Post subject: Reply with quote

Great script. It should probably be one of the things put in the forthcoming library of standard include files.
Back to top
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sun Apr 16, 2006 12:32 am    Post subject: Reply with quote

I updated the function again. This time it's even easier to use.
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
Terrapin



Joined: 15 Aug 2005
Posts: 107
Location: North Carolina

PostPosted: Sat Apr 22, 2006 10:20 am    Post subject: Reply with quote

Thank You, Titan.

Bob
_________________
When it comes to Binary, there are 10 types of people. Those who get it and those who don't. Smile
Back to top
View user's profile Send private message
AGU
Guest





PostPosted: Sat Apr 22, 2006 12:53 pm    Post subject: Reply with quote

Quote:
It should probably be one of the things put in the forthcoming library of standard include files.
Does this library already exist?
___________________
Cheers
AGU
Back to top
AGU
Guest





PostPosted: Sat Apr 22, 2006 8:05 pm    Post subject: Reply with quote

It's me again. As I'm using an older version of this function in BBCodeWriter I thought about updating to your new one. But I don't get the point of how to use it. Could you give me a short example?

I meanwhile took your old function and replaced GuiControl, Move with GuiControl, MoveDraw to workaround a displaying error when resizing the GUI in x-direction.

This is your older one:
Code:
Anchor(Control, Anchors="", x=0, y=0, w=0, h=0)
  { 
    ; Thanks to Titan for this function
    ; Details under http://www.autohotkey.com/forum/viewtopic.php?p=26778
   
    ; Control         : Variable assigned to the control (e.g. "MyEdit")
    ; Anchors         : How control to be moved (e.g. "xy" for position or "wh" for size)
    ; x, y, w, h      : respective values of control
    ;                 (note you can omit values that aren't needed by the Anchors by putting any value)
   
    global GuiW, GuiH
   
    If (not Anchors)
      Anchors = xy
    If Anchors contains x
      GuiControl, MoveDraw, % Control, % "x" x+(A_GuiWidth-GuiW)
    If Anchors contains y
      GuiControl, MoveDraw, % Control, % "y" y+(A_GuiHeight-GuiH)
    If Anchors contains w
      GuiControl, MoveDraw, % Control, % "w" w+(A_GuiWidth-GuiW)
    If Anchors contains h
      GuiControl, MoveDraw, % Control, % "h" h+(A_GuiHeight-GuiH)
  }


I call it this way:
Code:
      ...
      Anchor("EdtComment", "wh", 0, 0, EdtW, EdtH)
      Anchor("GrpMenuBorder", "w", 0, 0, GrpW, 0)
      Anchor("ChkSig", "y", 0, ChkY, 0, 0)
      Anchor("DDLSig", "y", 0, DDLY, 0, 0)
      Anchor("BtnEditSig", "y", 0, BSgY, 0, 0)
      Anchor("BtnDelSig", "y", 0, BSgY, 0, 0)
      Anchor("BtnSend", "xy", BG1X, BG3Y, 0, 0)
      Anchor("BtnPreview", "xy", BG2X, BG3Y, 0, 0)
      Anchor("BtnReset", "xy", BG3X, BG3Y, 0, 0)
      Anchor("BtnPinned", "x", BG4X, 0, 0, 0)
      ...


How would I have to call your updated function? I tried to remove all anchors to make the syntax compatible to your new function but it didn't work.
Code:
      Anchor("EdtComment", 0, 0, EdtW, EdtH)

_______________
Cheers
AGU
Back to top
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sat Apr 22, 2006 8:31 pm    Post subject: Reply with quote

Replace the 0's with a blank value (i.e. ""). If you want to force a MoveDraw, specify an extra parameter of 1. Using your code the correct version would be: Anchor("EdtComment", "", "", EdtW, EdtH, 1).
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
AGU
Guest





PostPosted: Sun Apr 23, 2006 9:10 am    Post subject: Reply with quote

Thx Titan. I made the changes and it works great.

btw. wouldn't it be better to set Draw to 1? Because I spotted this displaying error when resizing a GUI in x-direction when using a normal move instead of a MoveDraw.



Therefore I predefined Draw to 1:
Code:
Anchor(Control, x=0, y=0, w=0, h=0, Draw=1)
  {
    ; Thanks to Titan for this function
    ; Details under http://www.autohotkey.com/forum/viewtopic.php?p=26778
   
    ; Control         : Variable assigned to the control (e.g. "MyEdit")
    ; x, y, w, h      : the anchor positions/dimensions
    ; Draw            : false/0 to use Move otherwise leave blank for a MoveDraw
 
    global GuiW, GuiH
    IfEqual, GuiW
      {
        SetEnv, GuiW, %A_GuiWidth%
      }
    IfEqual, GuiH
      {
        SetEnv, GuiH, %A_GuiHeight%
      }
    pos = xywh
    Loop, Parse, pos
      {
        If (%A_LoopField% != "")
          {
            If A_LoopField in x,w
              {
                v := %A_LoopField% + (A_GuiWidth - GuiW)
              }
            Else
              {
                v := %A_LoopField% + (A_GuiHeight - GuiH)
              }
            move := move . A_LoopField . v
          }
        IfNotEqual, Draw, 0
          {
            SetEnv, MDraw, Draw
          }
      }
    GuiControl, Move%MDraw%, %Control%, %move%
    Return, ErrorLevel
  }

__________________
Cheers
AGU
Back to top
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sun Apr 23, 2006 10:55 am    Post subject: Reply with quote

Setting Draw to 1 means a MoveDraw will be used instead. MoveDraw causes flickering with other controls like Edit so the standard Draw is better. If you have more buttons in your GUI then you can set Draw to 1 in the first line of the function without having to change anything else.
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sat Aug 12, 2006 9:11 pm    Post subject: Reply with quote

In version 2 you don't need to define GuiW or GuiH for multiple GUI's. I've also combined the x/y/w/h params so it's similar to GuiControl - see the example.
Older versions are still available for download.
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
Rajat



Joined: 28 Mar 2004
Posts: 1717

PostPosted: Sat Aug 12, 2006 9:38 pm    Post subject: Reply with quote

Titan,
I got late in testing out this nice function... its very well-made and works great.. thanks for posting!
_________________
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sat Aug 12, 2006 10:54 pm    Post subject: Reply with quote

Thanks. I have a bad habbit of not commenting my scripts and using short/cryptic variable names so I have to apologize if parts were hard to understand. Atleast this means they're smaller in size thus include-friendly Rolling Eyes
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3 ... 9, 10, 11  Next
Page 1 of 11

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group