in reply to Disable Control in Win32::GUI

I also tried to set the onClick event to an empty sub which didn't work either

Define "didn't work"? What did you expect that to do that didn't happen?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Disable Control in Win32::GUI
by ChrisR (Hermit) on Dec 19, 2005 at 21:49 UTC
    I guess this may be a little confusing but by "didn't work", I meant that the control was still "working." I am trying to disable the control without it turning gray so that it looks normal but does not respond to events.

      The confusing thing is your terminology. Your control is an textfield, and textfields don't do anything in response to single clicks, so setting an empty onClick handler isn't going to change it's behaviour.

      If you said "I want to stop the user from being able to edit the text displayed in the Textfield", then it would be fairly obvious that you don't want to 'disable the control', you want to 'set the TextField readonly', which is a fairly common thing to want to do to edit fields and there is therefore an option for doing exactly that (called -readonly :). Try this

      use strict; use Win32::GUI; use Win32::API; our $mainform = Win32::GUI::Window->new( -name=>'main', -text=>'main', ) or die "window creation failed: $!\n"; our $test = $mainform->AddTextfield( -name=>'test', -text=>'test', -left=>200,-top=>200, -width=>100,-height=>20, -readonly => 1, ) or die "control creation failed: $!\n"; $mainform->Show(); Win32::GUI::Dialog;

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I really did mean that I wanted to disable it. It's not just for a textfield but for any control. I wanted to turn off all responses for any given control (clicks, cursor changes, etc.) just like it was disabled. I just didn't want it to look like it was disabled. My guess was that the method Win32::GUI uses to disable a control calls multiple functions in the underlying api to achieve the final result. I was just looking for a way to do this without the steps that change the appearance of the control. I just don't know how this is done. I have looked win32.pm and gui.pm but just can't seem to figure it out.

        Update:
        Setting the -readonly property changes the appearance of the control by making the background gray. The idea is to keep it looking the same but non-functional.