flw wrote:
I want to write an editor use Win32::GUI;
So I hope I can process the KeyDown event for Textfield control by myself.
After some tries,
I can't disable the default action of Textfield in sub onKeyDown().

following is my code, any help would be appreciated.

Sorry, but it's not clear to me what you are trying to do. The code you post below does what I would expect it to. What are you expecting it to do, and what does it actually do?

Regards,
Rob.

#! perl -w

use strict;
use Win32::GUI;
use Data::Dumper;

my $CurrentFile = "";

my $EditFont = new Win32::GUI::Font (
        -name => "Fixedsys",
        -size => 12,
    );

# Create Main Window
our $Window = new Win32::GUI::Window (
    -name     => "Window",
    -title    => "Notepad",
    -pos      => [100, 100],
    -size     => [400, 400],
    -onResize   => \&Notepad_OnSize,

) or die "new Window";

my $count = 0;

# Create Textfield for Edit Text
$Window->AddTextfield(
    -name      => "Edit",
    -pos       => [0, 0],
    -size      => [100, 100],
    -multiline => 1,
    -hscroll   => 1,
    -vscroll   => 1,
    -autohscroll => 1,
    -autovscroll => 1,
    -keepselection => 1 ,
    -font => $EditFont,
    -onKeyDown => sub {
        my $key = $_[2];
        $Window->{StatusBar}->SetText( 0, sprintf( "value = [%d], char
= [%c], count = [%d]", $key, $key, $count++ ) );
        -1;
    },
);

$Window->AddStatusBar(
    -name => 'StatusBar',
);

# Set Focus to Edit and show Window
$Window->Edit->SetFocus();
$Window->Show();

Win32::GUI::Dialog();

#######################################################################
#  Window Event

# Resize Window
sub Notepad_OnSize {
  my ($self) = @_;
  my ($width, $height) = ($self->GetClientRect())[2..3];
  $self->Edit->Resize($width, $height-20) if exists $self->{Edit};
  $self->StatusBar->Resize($width, $height) if exists $self->{StatusBar};
}
__END__

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/



Reply via email to