一个同步的ScrollViewer WPF带滚动条的WinForms [英] Synchronizing a WPF ScrollViewer with a WinForms ScrollBar
问题描述
由于我目前的项目中一个尚未解决的问题[<一个href=\"http://stackoverflow.com/questions/5870516/weird-scrollbar-ui-in-hosted-wpf-composite-control\">Weird在承载的WPF复合控件滚动UI],我不得不推迟到解决方法。一个这样的想法,我想出了是保持的ScrollViewer问题与一个Windows窗体同步滚动条(水平和垂直)。我会如何做呢?
Due to an unsolved issue in my current project [ Weird scrollbar UI in hosted WPF composite control ], I've had to defer to workarounds. One such idea I came up with was to keep the ScrollViewer in question in sync with a Windows Forms ScrollBar (horizontal and vertical). How would I go about doing that?
在本质上,我要的WinForms滚动条(S)之类的ScrollViewers工作(在拖动的条款和事件类似的东西)。
In essence, I want the WinForms scrollbar(s) to work like the ScrollViewers (in terms of dragging and events suchlike).
推荐答案
我设法实现它,而无需多与周围的WinAPI的。以下是我做的:
I managed to implement it without having to much around with the WinAPI. Here's how I did it:
- 注册一个ScrollOffsetChanged事件处理程序与ScrollViewer中(复合控件实现的IScrollInfo接口公开的事件)。
- 注册一个ValueChanged事件处理程序与Windows窗体滚动条。
- 一对夫妇的信号旗,以prevent循环调用到事件处理程序。
- 第一个处理程序称为UpdateExternalScrollBars()函数,使用下面的前pression计算Maximium滚动条属性:ScrollViewer-> ExtentHeight /宽度 - ScrollViewer-> ViewportHeight /宽度。 Value属性直接设置为ScrollViewer->垂直/ HorizontalOffset。
- 第二个从形式滚动窗口获取的价值属性,并将其传递给ScrolViewer-> ScrollToVertial / HorizontalOffset()。信号旗被适当地预先设置。
这篇关于一个同步的ScrollViewer WPF带滚动条的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!