1

我有一个 wxTextCtrl,其中包含许多启用滚动条的文本行。在一个事件中,我想滚动到控件的末尾并重绘控件。

这是我所拥有的:

    def event_scroll_to_end(self, event):
        self.m_textCtrl1.SetScrollPos(
            wx.VERTICAL,
            self.m_textCtrl1.GetScrollRange(wx.VERTICAL))
        event.Skip()

这会滚动到最后并更新/重绘滚动条本身,但它不会更新 textCtrl,它仍然显示滚动到其当前位置。

我怎样才能真正滚动 textCtrl 以便内容滚动到最后,如滚动条所示?

4

3 回答 3

1

我怀疑你需要设置插入点,如果你想定位在文本的末尾,即

def event_scroll_to_end(self, event):
    self.m_textCtrl1.SetScrollPos(
        wx.VERTICAL,
        self.m_textCtrl1.GetScrollRange(wx.VERTICAL))
    self.m_textCtrl1.SetInsertionPoint(-1)
    event.Skip()

用于SetInsertionPoint(0)将自己定位在文本的开头。

于 2019-03-25T11:09:32.747 回答
0

ShowPosition函数可用于通过显示缓冲区的最后位置滚动到末尾。

    def event_scroll_to_end(self, event):
        self.m_textCtrl3.ShowPosition(self.m_textCtrl3.GetLastPosition())
        event.Skip()
于 2019-03-25T13:35:09.533 回答
-1

我也一直在为此苦苦挣扎。最后,以下对我有用:

    mywindow.SetInsertionPoint(-1)
    mywindow.ShowPosition(mywindow.GetLastPosition())
    mywindow.Refresh()
    mywindow.Update()
于 2019-07-18T06:48:47.200 回答