进度条升级Perl Win32 :: GUI

时间:2012-03-23 06:18:37

标签: perl win32gui

我正在使用perl Win32 :: GUI开发桌面应用程序。我正在使用Progress Bar进行状态识别。 我已将进度条的最大级别设置为100.在此我按照长度逐步增加值。 我在下面写了示例代码。我通过将100除以输入长度来计算升压值。在那里,如果输入长度是奇数,则步长值将是浮点数。因此,进度条未完全完成其最高级别。 例如,如果长度为11,则步进值为9.09。 进度条仅将其设为9。因此,进度水平仅完成99个细分。不是100.请分享您的建议。

use strict;
use Win32;
use Win32::GUI;

my $DOS = Win32::GUI::GetPerlWindow();                   
Win32::GUI::Hide($DOS);

my $Upload_win=Win32::GUI::Window->new(
        -name => 'UploadWindow',
        -text => 'SVN-CHIP-Upload-Tool-V2-HurixSystems',
        -left => 375,
        -top  => 400,
        -width =>520,#370,
        -height =>520,
        #-menu =>$Menu,
        -background => [190,190,190],
        -dialogui   => 1,
        -maximizebox => 0,
);

my $ProcessButton=$Upload_win->AddButton(
        -text => 'Upload',
        -name =>  'uploadbut',
        -size => [90,25],
        -pos  =>  [200,360],
        -background =>  [190,190,190],
        -foreground => [],
        -tabstop => 1,
);
my $Progress_bars=$Upload_win->AddProgressBar(
  -pos=>[20,400],
  -background=>[0,255,85],
  -smooth   => 1,
  -size=>[470,20],

);

$Upload_win->Show();
Win32::GUI::Dialog();
Win32::GUI::Hide($DOS);

sub uploadbut_Click{

  $Progress_bars->SetRange(0,100);
  my $x=11;
  my $y=100/$x;
  for(1..$x){
  Win32::GUI::DoEvents() >= 0;
   $Progress_bars->SetStep($y);
   $Progress_bars->StepIt();
   sleep 1;
  }
}

1 个答案:

答案 0 :(得分:2)

您可以将进度条的长度设置为步骤的乘积和步长:

#!perl

use strict;
use Win32;
use Win32::GUI();

my $DOS = Win32::GUI::GetPerlWindow();                   
Win32::GUI::Hide($DOS);

my $Upload_win=Win32::GUI::Window->new(
    -name => 'UploadWindow',
    -text => 'SVN-CHIP-Upload-Tool-V2-HurixSystems',
    -left => 375,
    -top  => 400,
    -width => 520,
    -height =>520,
    -background => [190,190,190],
    -dialogui   => 1,
    -maximizebox => 0,
);

my $ProcessButton=$Upload_win->AddButton(
    -text => 'Upload',
    -name =>  'uploadbut',
    -size => [90,25],
    -pos  =>  [200,360],
    -background =>  [190,190,190],
    -foreground => [],
    -tabstop => 1,
);
my $Progress_bars=$Upload_win->AddProgressBar(
    -pos=>[20,400],
    -background=>[0,255,85],
    -smooth   => 1,
    -size=>[470,20],
);

$Upload_win->Show();
Win32::GUI::Dialog();
Win32::GUI::Hide($DOS);

sub uploadbut_Click{
    my $intended_max = 100;
    my $x = 11;
    my $y = int($intended_max/$x);

    $Progress_bars->SetRange(0,$x*$y);

    for(1 .. $x){
        Win32::GUI::DoEvents();
        $Progress_bars->SetStep($y);
        $Progress_bars->StepIt();
        Win32::Sleep(1000);
    }
}