一个同步的ScrollViewer WPF带滚动条的WinForms [英] Synchronizing a WPF ScrollViewer with a WinForms ScrollBar

查看:493
本文介绍了一个同步的ScrollViewer WPF带滚动条的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我目前的项目中一个尚未解决的问题[<一个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:


  1. 注册一个ScrollOffsetChanged事件处理程序与ScrollViewer中(复合控件实现的IScrollInfo接口公开的事件)。

  2. 注册一个ValueChanged事件处理程序与Windows窗体滚动条。

  3. 一对夫妇的信号旗,以prevent循环调用到事件处理程序。

  4. 第一个处理程序称为UpdateExternalScrollBars()函数,使用下面的前pression计算Maximium滚动条属性:ScrollViewer-> ExtentHeight /宽度 - ScrollViewer-> ViewportHeight /宽度。 Value属性直接设置为ScrollViewer->垂直/ Horizo​​ntalOffset。

  5. 第二个从形式滚动窗口获取的价值属性,并将其传递给ScrolViewer-> ScrollToVertial / Horizo​​ntalOffset()。信号旗被适当地预先设置。

这篇关于一个同步的ScrollViewer WPF带滚动条的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆