Jump to content

Edit Control: Readonly toggle


blindwig
 Share

Recommended Posts

I have an edit control that I want to be able to toggle weather or not it is read-only in the script.

I want to do this because I want the control to be readonly for certain conditions. I don't want to use GUICtrlSetState and $GUI_Disable because then the scroll bars don't work.

But it seems like you can't affect the readonly status of an edit control once the control is created.

Try this:

$hndEdit_Test1 = GUICtrlCreateEdit("test1", 0, 0, 100, 100, 0)
GUICtrlSetStyle($hndEdit_Test1, $ES_Readonly)
; Notice that the control is not readonly


$hndEdit_Test1 = GUICtrlCreateEdit("test1", 0, 0, 100, 100, $ES_Readonly)
GUICtrlSetStyle($hndEdit_Test1, 0)
; Notice that the control stays readonly

The only thing I can think to do is when I want to change it, I need to save the data then destory it and create another edit box of the same size and shape and re-populate it.

Link to comment
Share on other sites

Based on this recent post, try the following GuiCtrlSendMsg:

#include <GuiConstants.au3>
Global $EM_SETREADONLY = 0xCF;

GuiCreate("Example")

$hndEdit_Test1 = GUICtrlCreateEdit("test1", 0, 0, 100, 100, 0)
$hndEdit_Test1 = GUICtrlCreateEdit("test1", 0, 0, 100, 100, $ES_Readonly)

GuiSetState()

GuiCtrlSendMsg($hndEdit_Test1, $EM_SETREADONLY, 0, 0);not read-only
sleep(1000)
GuiCtrlSendMsg($hndEdit_Test1, $EM_SETREADONLY, 1, 0);read-only
sleep(1000)
GuiCtrlSendMsg($hndEdit_Test1, $EM_SETREADONLY, 0, 0);not read-only

While GuiGetMsg() <> $GUI_EVENT_CLOSE
    sleep(100)
WEnd
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Based on this recent post, try the following GuiCtrlSendMsg:

#include <GuiConstants.au3>
Global $EM_SETREADONLY = 0xCF;

GuiCreate("Example")

$hndEdit_Test1 = GUICtrlCreateEdit("test1", 0, 0, 100, 100, 0)
$hndEdit_Test1 = GUICtrlCreateEdit("test1", 0, 0, 100, 100, $ES_Readonly)

GuiSetState()

GuiCtrlSendMsg($hndEdit_Test1, $EM_SETREADONLY, 0, 0);not read-only
sleep(1000)
GuiCtrlSendMsg($hndEdit_Test1, $EM_SETREADONLY, 1, 0);read-only
sleep(1000)
GuiCtrlSendMsg($hndEdit_Test1, $EM_SETREADONLY, 0, 0);not read-only

While GuiGetMsg() <> $GUI_EVENT_CLOSE
    sleep(100)
WEnd

<{POST_SNAPBACK}>

in the current beta I did a correction to do the EM_setREADONLY when you request ES_READONLY by GUICtrlSetStyle

Can you verify it is OK? :)

Link to comment
Share on other sites

Like this? If so I think $EM_SETREADONLY should be included in the help file and in GUIConstants.au3.

#include <GUIConstants.au3>

$EM_SETREADONLY = 0xCF

GUICreate("Test")

$Check = GUICtrlCreateCheckbox ("Check", 10, 10, 120, 20)

$Edit = GUICtrlCreateEdit("Edit", 50, 50, 100, 100)

GUISetState()

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then Exitloop
   If GUICtrlRead($Check) = $GUI_CHECKED then
      GUICtrlSetStyle($Edit, $ES_READONLY)
   Else
      GUICtrlSetStyle($Edit, $EM_SETREADONLY)
   EndIf
WEnd

qq

Link to comment
Share on other sites

Like this? If so I think $EM_SETREADONLY should be included in the help file and in GUIConstants.au3.

<{POST_SNAPBACK}>

NO,NO

like that there is no need at least for this style modification just set ES_READONLY or reset GUI_SS_DEFAULT_EDIT

#include <GUIConstants.au3>

GUICreate("Test")

$Check = GUICtrlCreateCheckbox ("Check", 10, 10, 120, 20)

$Edit = GUICtrlCreateEdit("Edit", 50, 50, 100, 100)

GUISetState()

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then Exitloop
    if $msg=$check then
       If GUICtrlRead($Check) = $GUI_CHECKED then
          GUICtrlSetStyle($Edit, $ES_READONLY)
       Else
          GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT)
       EndIf
   endif
WEnd
:)
Link to comment
Share on other sites

Ohhhhhhh. :), I still think it should be included but, $EM_SETREADONLY that is.

<{POST_SNAPBACK}>

Your example works just because you try to use $em_setreadonly which is not doing anything except not setting $es_readonly, so it is wrong to use with GuiCtrlSetStyle with this parameter.

definetly it can be use with GUICtrlSendMsg but as we don't document all those msg we don't include them in the GUIConstants.au3 or in Constants.au3.

I hope that clarify how to use es_readonly :D

Link to comment
Share on other sites

NO,NO

like that there is no need at least for this style modification just set ES_READONLY or reset GUI_SS_DEFAULT_EDIT

#include <GUIConstants.au3>

GUICreate("Test")

$Check = GUICtrlCreateCheckbox ("Check", 10, 10, 120, 20)

$Edit = GUICtrlCreateEdit("Edit", 50, 50, 100, 100)

GUISetState()

While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Then Exitloop
    if $msg=$check then
       If GUICtrlRead($Check) = $GUI_CHECKED then
          GUICtrlSetStyle($Edit, $ES_READONLY)
       Else
          GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT)
       EndIf
   endif
WEnd
:D

<{POST_SNAPBACK}>

Oddly, that example doesn't do anything to the readonly-ness :)
FootbaG
Link to comment
Share on other sites

I notice that an Edit will change colour when you apply the ReadOnly style to it. Should not Input's do the same?

Basically why I ask is I was trying to duplicate this effect without having to manually change the background color:

Posted Image

Heh, noticing a weird bug too... have a look at this:

CODE
#include <GUIConstants.au3>

GUICreate("Test")

$Check = GUICtrlCreateCheckbox ("Check", 10, 10, 120, 20)

$Input = GUICtrlCreateInput("Input", 50, 30, 100, 20)

$Edit = GUICtrlCreateEdit("Edit", 50, 50, 100, 100)

GUISetState()

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then Exitloop

if $msg=$check then

If GUICtrlRead($Check) = $GUI_CHECKED then

GUICtrlSetStyle($Input, $ES_READONLY)

GUICtrlSetState($Input, $GUI_DISABLE)

GUICtrlSetStyle($Edit, $ES_READONLY)

GUICtrlSetState($Edit, $GUI_DISABLE)

Else

GUICtrlSetStyle($Input, $GUI_SS_DEFAULT_INPUT)

GUICtrlSetState($Input, $GUI_ENABLE)

GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT)

GUICtrlSetState($Edit, $GUI_ENABLE)

EndIf

endif

WEnd

Note the text color and lack of scroll bars if you toggle back and forth.

Link to comment
Share on other sites

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...