Sign in to follow this  
Followers 0
ReverendJ1

Dynamic Button Spacing

3 posts in this topic

Hello everyone, I am trying to write my first program with AutoITScript v3. I am trying to write a program that will make a button for each cd drive on a computer that when pressed will close that cd-tray. Sounds dumb, but is good for when you are remotely connected to a computer. Anywho, I made a little headway, and now I am stuck. I have figured out how to make the buttons, but I can't figure out how to space them right. The code below will make it so you can't see the first button/drive. Can anyone help me? I'm sure it is really easy.

#include <GUIConstants.au3>

$arrDrives = DriveGetDrive( "CDROM" )

GUICreate("My GUI Button") ; will create a dialog box that when displayed is centered

Opt("GUICoordMode",0)

If NOT @error Then

$numXCoordinates = 0

$numYCoordinates = 0

For $i = 1 to $arrDrives[0]

GUICtrlCreateButton (StringUpper($arrDrives[$i]), $numXCoordinates, $numYCoordinates, 25, 25)

If $i > 1 Then

$numXCoordinates = 28

EndIf

Next

GUISetState () ; will display an dialog box with 2 button

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

EndIf

Share this post


Link to post
Share on other sites



Hmmm. That didn't work either, that was what I had originally tried. I have three drives, and that still places the second drive/button over top of the first one. I guess it doesn't really matter, because I think you are right with the using a combo/list box. I just saw that you could create a dynamic GUI easily with AutoIT and wanted to play around with it.

Share this post


Link to post
Share on other sites

No, those didn't really work. The spaces grow after each button. I had it right the first time, sort of. I just realized what happened, and I am an idiot. I changed the spacing after I used the spacing variable. Therefore, the spacing stayed 0 for 2 passes, instead of one. It should read like this:

For $i = 1 to $arrDrives[0]
    If $i > 1 Then
        $numXCoordinates = 28
    EndIf
    GUICtrlCreateButton (StringUpper($arrDrives[$i]), $numXCoordinates, $numYCoordinates, 25, 25)
Next

Note that I change $numXCoordinates before I call it the second time.

Share this post


Link to post
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
Sign in to follow this  
Followers 0