Jump to content
Sign in to follow this  
thanhlam

"IsChecked" not working

Recommended Posts

thanhlam

Hi, I try to use AutoIt to control a soft I have written in C# 4.0.
I can start, stop the software, change the state of the checkbox.

  • Something strange to uncheck the check box:
    ; check the checkbox (working fine)
    ControlCommand($win, "", $checkbox, "Check", "")
    
    ; uncheck the checkbox (NOT WORKING)
    ControlCommand($win, "", $checkbox, "UnCheck", ""
    
    ; uncheck the checkbox (working)
    ControlCommand($win, "", $checkbox, "Check", "")
  • Unfortunately I did not managed to get the check box status using :
    $res = ControlCommand($win, "", $checkbox, "IsChecked", "")​

Share this post


Link to post
Share on other sites
thanhlam

How can I add a 7z with the content of the script and a test program in C#4.0 to illustrate my post ?

Share this post


Link to post
Share on other sites
michaelslamet

This might doesn't help, but do you notice that you lack a ")" at the end of non-working checkbox line?

Share this post


Link to post
Share on other sites
thanhlam

Hi,

thanks for replying but this is only a copy/paste error, that's why I wanted to attach an archive with my sample but I did not find how to upload the archive.

Share this post


Link to post
Share on other sites
saudumm

You can attach a file using the full editor.

post-65042-0-78476900-1378816028_thumb.p

Share this post


Link to post
Share on other sites
thanhlam

Hi Saudumm,

Could you be more specific in how to attach the file ? I trye to use "My media" but it propose only to select content that have been uploaded. I found no way to upload a file :

Share this post


Link to post
Share on other sites
saudumm

Hi Saudumm,

Could you be more specific in how to attach the file ? I trye to use "My media" but it propose only to select content that have been uploaded. I found no way to upload a file :

In the full editor there's "Attach Files" under the editor window. There you can select a file from your computer (1) and upload it (2). After that you can attach it to your post (3) :-)

post-65042-0-48997600-1378816901_thumb.p

Share this post


Link to post
Share on other sites
thanhlam

Thanks for your help Saudumm,

but even in the full editor, just under the textbox I immediately have the "Add Reply, Preview Post or Cancel" line.

There is nothing in between that would allow me to attach a file (sorry I cannot attach a screenshot to show you  :D)

There must be a setting somewhere that prevent me from adding files (I just created my account today).

Regards

Share this post


Link to post
Share on other sites
somdcomputerguy

There's probably a new user post count that must be met to allow files to be uploaded. You should post all of your au3 code to get better help.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
saudumm

Maybe this option isn't available for new members. This is my 8. post but I'm registered since 2011  and I'm a normal member.

Could you upload your file to Dropbox or something else and share the link?

Share this post


Link to post
Share on other sites
thanhlam

Here is the link to the visual studio project in C# and the test.au3

https://www.dropbox.com/s/fqy75h0qdbou3et/test.7z

Here is the code of test.au3.

 
$path = "WindowsFormsApplication1WindowsFormsApplication1binDebug"
$bin = "WindowsFormsApplication1.exe"
$soft = "[CLASS:WindowsForms10.Window.8.app.0.2bf8098_r20_ad1]"
$checkbox = "[NAME:cbTest]"
$checkbox2 = "[CLASS:WindowsForms10.BUTTON.app.0.2bf8098_r20_ad1; INSTANCE:1]"
 
Run($path & $bin, $path)
$win = WinWaitActive($soft)
 
; "Uncheck" is not working, have to "Check" a 2nd time to uncheck...
ControlCommand($win, "", $checkbox, "Check", "")
Sleep(500)
ControlCommand($win, "", $checkbox, "Check", "")
Sleep(500)
ControlCommand($win, "", $checkbox, "Check", "")
Sleep(500)
$res = ControlCommand($win, "", $checkbox, "IsChecked", "")
if 1 = @error Then
   MsgBox(4, "ERROR", "ERROR")
Else
   MsgBox(4, "IsChecked", $res)
EndIf
 
; Using class
ControlCommand($win, "", $checkbox2, "Check", "") ; uncheck
Sleep(500)
ControlCommand($win, "", $checkbox2, "Check", "") ; recheck
Sleep(500)
$res = ControlCommand($win, "", $checkbox2, "IsChecked", "")
if 1 = @error Then
   MsgBox(4, "ERROR", "ERROR")
Else
   MsgBox(4, "IsChecked", $res)
EndIf
 
WinClose($soft)

 

Share this post


Link to post
Share on other sites
dragan

It is good thing that you have control over your own .NET application. My advice is this:

- Open your C# project, in the Form select your checkbox, click on the thunder icon (events icon), and double click on the event for "KeyDown"
- Then in your C# code make sure you add this code:
 

private void cbTest_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.F8)
    {
        cbTest.Checked = true;
    }
    else if (e.KeyCode == Keys.F12)
    {
        cbTest.Checked = false;
    }
}

- Then make sure you use this in your autoit script:
 

$path = "WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\"
$bin = "WindowsFormsApplication1.exe"
$soft = "Form1"
$checkbox = "[NAME:cbTest]"

Run($path & $bin, $path)
$win = WinWaitActive($soft)

ControlSend($win, '', $checkbox, "{F8}")
MsgBox(0, '', 'it is checked!')
ControlSend($win, '', $checkbox, "{F12}")
MsgBox(0, '', 'it is unchecked!')

WinClose($soft)

Edit: Another idea:
You could create a local TCP connection between autoit and your C# application, and then exchange informations (i.e. checked state), and make requests for checking/unchecking checkboxes or controlling other controls.

 

Edited by dragan

Share this post


Link to post
Share on other sites
thanhlam

Thanks everyone for the replies

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  

×