Sign in to follow this  
Followers 0
taurus905

Button Moving and Sizing with hotkeys.

9 posts in this topic

#1 ·  Posted (edited)

I wrote the following script in an attempt to be able to move a button around inside of a gui using hotkeys.

I know there must be a better way, since this one flickers when you first run it, but it does work.

I need to get some sleep soon, but I would appreciate any ideas.

I would also like to be able to resize the button with hotkeys also.

Eventually, I will have a number of buttons in the gui.

Thanks,

taurus905

; Button Moving and Sizing Test.au3
#include <GUIConstants.au3>

HotKeySet("!{LEFT}", "_Move_Button_Left"); ALT-Left =  Move Button Left
HotKeySet("!{RIGHT}", "_Move_Button_Right"); ALT-Right =  Move Button Right
HotKeySet("!{UP}", "_Move_Button_Up"); ALT-Up =  Move Button Up
HotKeySet("!{DOWN}", "_Move_Button_Down"); ALT-Down =  Move Button Down

$text_1 =  "Button 1"
$x_1 = 10
$y_1 = 10
$w_1 = 60
$h_1 = 25

$Main = GUICreate("Button Moving and Sizing Test", 300, 300, -1, -1, $WS_OVERLAPPEDWINDOW); Create $Main GUI
$Button_1 = GUICtrlCreateButton($text_1, $x_1, $y_1, $w_1, $h_1)
GUISetState(@SW_SHOW, $Main)

While 1
    $msg = GUIGetMsg()
    If $msg = 1 Or $msg = 2 Or $msg = 3 Or $msg = 4 Then _Move_Button()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Exit

Func _Move_Button_Left(); Move Button Left
    $x_1 -= 1
    $msg = 1
EndFunc

Func _Move_Button_Right(); Move Button Right
    $x_1 += 1
    $msg = 2
EndFunc

Func _Move_Button_Up(); Move Button Up
    $y_1 -= 1
    $msg = 3
EndFunc

Func _Move_Button_Down(); Move Button Down
    $y_1 += 1
    $msg = 4
EndFunc

Func _Move_Button(); Move Button
        GUICtrlDelete($Button_1)
        $Button_1 = GUICtrlCreateButton($text_1, $x_1, $y_1, $w_1, $h_1)
EndFunc

Edited: If $msg = 1 Or 2 Or 3 Or 4 Then

To: If $msg = 1 Or $msg = 2 Or $msg = 3 Or $msg = 4 Then

I knew I was tired. :D

Edited by taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You are defining msg twice. I think that will not even work.

It would be best if you replaced the $msg = in your Move functions just by a _Move_Button call. I hope this was clear to you.

Edit:

; Button Moving and Sizing Test.au3
#include <GUIConstants.au3>

HotKeySet("!{LEFT}", "_Move_Button_Left"); ALT-Left =  Move Button Left
HotKeySet("!{RIGHT}", "_Move_Button_Right"); ALT-Right =  Move Button Right
HotKeySet("!{UP}", "_Move_Button_Up"); ALT-Up =  Move Button Up
HotKeySet("!{DOWN}", "_Move_Button_Down"); ALT-Down =  Move Button Down

$text_1 =  "Button 1"
$x_1 = 10
$y_1 = 10
$w_1 = 60
$h_1 = 25

$Main = GUICreate("Button Moving and Sizing Test", 300, 300, -1, -1, $WS_OVERLAPPEDWINDOW); Create $Main GUI
$Button_1 = GUICtrlCreateButton($text_1, $x_1, $y_1, $w_1, $h_1)
GUISetState(@SW_SHOW, $Main)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
Exit

Func _Move_Button_Left(); Move Button Left
    $x_1 -= 1
    _Move_Button()
EndFunc

Func _Move_Button_Right(); Move Button Right
    $x_1 += 1
    _Move_Button()
EndFunc

Func _Move_Button_Up(); Move Button Up
    $y_1 -= 1
    _Move_Button()
EndFunc

Func _Move_Button_Down(); Move Button Down
    $y_1 += 1
   _Move_Button()
EndFunc

Func _Move_Button(); Move Button
        GUICtrlDelete($Button_1)
        $Button_1 = GUICtrlCreateButton($text_1, $x_1, $y_1, $w_1, $h_1)
EndFunc

This is what i meant.

Edited by Manadar

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Lol you don't have any views but you do have 2 replies?

[edit] Same in other post.

Edited by Manadar

Share this post


Link to post
Share on other sites

Lol you don't have any views but you do have 2 replies?

[edit] Same in other post.

Manadar,

I noticed the 'view count' problem last night too on another post.

Thanks for the help. I see where I went wrong.

My logic gets a little fuzzy this time off the morning.

I'm a night person.

taurus905


"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Share this post


Link to post
Share on other sites

Manadar,

I noticed the 'view count' problem last night too on another post.

Thanks for the help. I see where I went wrong.

My logic gets a little fuzzy this time off the morning.

I'm a night person.

taurus905

It's 3 PM here so i don't have any problems with that sort of things at all.

Isn't that lovely, we complete eachother :D lol

Share this post


Link to post
Share on other sites

Might be better than deleting the button over and over:

Func _Move_Button(); Move Button
    ControlMove($Main, '', $Button_1, $x_1, $y_1, $w_1, $h_1)
EndFunc


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Might be better than deleting the button over and over:

Func _Move_Button(); Move Button
    ControlMove($Main, '', $Button_1, $x_1, $y_1, $w_1, $h_1)
EndFunc
GUICtrlSetPos

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

GUICtrlSetPos

Yeah, well that's the proper way, what if I want to just confuse the hell out of somone or something, then you come along and spoil all the fun :D :D

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Yeah, well that's the proper way, what if I want to just confuse the hell out of somone or something, then you come along and spoil all the fun :D :D

SmOke_N,

I was already so confused that any more confusion could only put me back on the right path. :">

Anyway, good teamwork SmOke_N and Gary. It is finally working the way I want it to.

11:23am; way past my bedtime. :P

Have a great day guys.

taurus905


"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

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