如何使用 Win32::GUI 重置 Perl 中的垂直滚动位置?

发布于 2024-08-16 04:57:44 字数 950 浏览 3 评论 0原文

我正在使用 Win32::GUI 创建的文本字段输出一些内容,如下所示:

$Object->AddTextfield(
        -name   => "Birthchart",
        -left   => 75,
        -top    => 90,
        -width  => 250,
        -height => 250,
        -vscroll =>1,
        -multiline => 1,
        -prompt => "Birthchart",        
    );


    {#do something here....
     }
$Object->Birthchart->Append($Content);

问题是:它自动将我带到输出的末尾,但我想从头开始读取输出,而不必向上滚动。稍后再向下滚动就可以了。

我可以使用下面的代码

$Object->Birthchart->GetFirstVisibleLine();

来获取最上面可见行的行号,但是如何将最上面可见行的行号设置为0呢?

代码 $Object->Birthchart->ResetFirstVisibleLine() 不起作用。

有什么建议吗?提前致谢。

更新

尝试了以下代码

$Object->Birthchart->ScrollPos(1,0);

但仍然不起作用。滚动条似乎已重置,但我仍然必须单击滚动条才能查看文本字段内容的开头。

I'm outputting something to the textfield I created using Win32::GUI, like this:

$Object->AddTextfield(
        -name   => "Birthchart",
        -left   => 75,
        -top    => 90,
        -width  => 250,
        -height => 250,
        -vscroll =>1,
        -multiline => 1,
        -prompt => "Birthchart",        
    );


    {#do something here....
     }
$Object->Birthchart->Append($Content);

The problem is: it automatically takes me to the end of the output but I want to read the output from the beginning without having to scroll up. It's okay to scroll down later.

I can use the following code

$Object->Birthchart->GetFirstVisibleLine();

to obtain the number of the uppermost visible line, but how can I set the number of the uppermost visible line to 0?

The code $Object->Birthchart->ResetFirstVisibleLine() doesn't work.

Any suggestions? Thanks in advance.

Update

Tried the following code

$Object->Birthchart->ScrollPos(1,0);

But it still doesn't work. The scrollbar seems to be reset but I still have to click on the scrollbar to view the beginning of the textfield content.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我喜欢麦丽素 2024-08-23 04:57:44

解决我的问题:

my @sel =$Object->Birthchart->GetSel();
$Object->Birthchart->Append($Content);
$Object->Birthchart->SetSel(@sel);
$Object->Birthchart->ScrollCaret();
$Object->Birthchart->SetFocus();

ScrollPos 似乎重置了滚动条位置但内容没有更新的原因是因为 ScrollPos() 只作用于滚动条。它不会更新文本字段的内容。

非常感谢 Anonymous Monk @perlmonks.org :) 原始答案位于此处

The fix to my problem:

my @sel =$Object->Birthchart->GetSel();
$Object->Birthchart->Append($Content);
$Object->Birthchart->SetSel(@sel);
$Object->Birthchart->ScrollCaret();
$Object->Birthchart->SetFocus();

The reason why ScrollPos seems to have reset the scrollbar position but the content hasn't been updated is because ScrollPos() only acts on the scrollbar. It does not update the content of the textfield.

Many thanks to Anonymous Monk @perlmonks.org :) and the original answer is here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文