in reply to How do I recognize that the user has pressed enter inside a text box? Win32::GUI Question
use strict; use Win32::GUI; my $win = new Win32::GUI::Window( -name => "Window", -text => "Test", -width => 200, -height => 100, -left => 200, -top => 100, -minsize => [200, 100], ); my $TextClass = new Win32::GUI::Class( -name => "_Editor", -extends => "RichEdit", -widget => "RichEdit", ); my $SearchText = $win->AddRichEdit ( -class => $TextClass, -left => 10, -top => 10, -width => 170, -height => 52, -text=>"", -name=>"searchtext", ); sub searchtext_KeyPress { my($key) = @_; if ($key == 13) { print "Enter!\n"; } return 1; } sub Window_Terminate { exit; return -1; } $win->Show(); Win32::GUI::Dialog();
UPDATE:
Above code works with RichEdit. If you want to recognize enter press on a Textfield, recent rumours on the Win32::GUI mailing list, point me to this:Thanks to John Rogers to show us the trick (with a little fix from me ;) )use strict; use Win32::GUI; my $win = new Win32::GUI::Window( -name => "Window", -text => "Test", -width => 200, -height => 100, -left => 200, -top => 100, -minsize => [200, 100], ); my $SearchText = $win->AddTextfield ( -left => 10, -top => 10, -width => 170, -height => 52, -text=>"", -name=>"searchtext", -multiline=>1, ); sub searchtext_Change{ my $rtest = 0; my $input =''; $input=$SearchText->Text(); $rtest = $input=~/\r\n$/; if($rtest){print "Enter!\n";} } sub Window_Terminate { exit; return -1; } $win->Show(); Win32::GUI::Dialog();
|
|---|