使用滚动一个备忘录编辑也可以滚动另一个备忘录

发布于 2024-10-19 17:58:16 字数 211 浏览 3 评论 0原文

我有两个相似的备忘录编辑(为了比较两个记录)我想保持滚动同步以方便比较。

我原本以为会有一个 OnScroll 事件,但没有看到一个,也没有看到任何类似的东西,我看到的最接近的是 Spin,这处理了一些可能性,但不是全部。

我也没有找到导航行的方法。

我确实看到了 ScrollToCaret 方法,但这并没有达到我想要的效果。

有什么想法吗?

I've got two memoedits which are similar (in order to compare two records) I would like to keep the scrolling in synch to ease comparison.

I had originally thought there would be an OnScroll event, but didn't see one, nor anything similar, the closest I saw was Spin, this handles some possibilities, but not all.

I also didn't see a way to navigate the rows.

I did see the ScrollToCaret method, but this doesn't do what I want.

Any ideas?

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

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

发布评论

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

评论(1

狂之美人 2024-10-26 17:58:16

这只能使用反射来实现。下面是显示如何同步垂直滚动条位置的代码:

using System.Reflection;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.ScrollHelpers;

    DevExpress.XtraEditors.ScrollHelpers.ScrollBarEditorsAPIHelper helper1, helper2;

            private void RibbonForm1_Load(object sender, EventArgs e) {
                FieldInfo fi = typeof(MemoEdit).GetField("scrollHelper", BindingFlags.NonPublic | BindingFlags.Instance);
                helper1 = fi.GetValue(memoEdit1) as DevExpress.XtraEditors.ScrollHelpers.ScrollBarEditorsAPIHelper;
                helper2 = fi.GetValue(memoEdit2) as DevExpress.XtraEditors.ScrollHelpers.ScrollBarEditorsAPIHelper;
                helper1.VScroll.ValueChanged += new EventHandler(VScroll_ValueChanged);
                helper2.VScroll.ValueChanged += new EventHandler(VScroll_ValueChanged);
            }

            void VScroll_ValueChanged(object sender, EventArgs e) {
                DevExpress.XtraEditors.VScrollBar scrollBar = sender as DevExpress.XtraEditors.VScrollBar;
                ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.ThumbPosition, scrollBar.Value);
                MemoEdit memo = ((MemoEdit)scrollBar.Parent);
                ScrollBarEditorsAPIHelper helper = helper1;
                if(memo == memoEdit1) 
                    helper = helper2;
                helper.VScroll.Value = scrollBar.Value;
                 MethodInfo mi = typeof(ScrollBarEditorsAPIHelper).GetMethod("UpdateOriginalScroll", BindingFlags.NonPublic | BindingFlags.Instance);
                 mi.Invoke(helper, new object[] { args, false });
            }

如果您还想同步水平滚动条位置,您应该订阅 HScrollbar.ValueChanged 事件。除了最后一行之外,代码应该几乎相同:

mi.Invoke(helper, new object[] { args, true });

This can be implemented using reflection only. Here is the code showing how to synchronize vertical scrollbar position:

using System.Reflection;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.ScrollHelpers;

    DevExpress.XtraEditors.ScrollHelpers.ScrollBarEditorsAPIHelper helper1, helper2;

            private void RibbonForm1_Load(object sender, EventArgs e) {
                FieldInfo fi = typeof(MemoEdit).GetField("scrollHelper", BindingFlags.NonPublic | BindingFlags.Instance);
                helper1 = fi.GetValue(memoEdit1) as DevExpress.XtraEditors.ScrollHelpers.ScrollBarEditorsAPIHelper;
                helper2 = fi.GetValue(memoEdit2) as DevExpress.XtraEditors.ScrollHelpers.ScrollBarEditorsAPIHelper;
                helper1.VScroll.ValueChanged += new EventHandler(VScroll_ValueChanged);
                helper2.VScroll.ValueChanged += new EventHandler(VScroll_ValueChanged);
            }

            void VScroll_ValueChanged(object sender, EventArgs e) {
                DevExpress.XtraEditors.VScrollBar scrollBar = sender as DevExpress.XtraEditors.VScrollBar;
                ScrollEventArgs args = new ScrollEventArgs(ScrollEventType.ThumbPosition, scrollBar.Value);
                MemoEdit memo = ((MemoEdit)scrollBar.Parent);
                ScrollBarEditorsAPIHelper helper = helper1;
                if(memo == memoEdit1) 
                    helper = helper2;
                helper.VScroll.Value = scrollBar.Value;
                 MethodInfo mi = typeof(ScrollBarEditorsAPIHelper).GetMethod("UpdateOriginalScroll", BindingFlags.NonPublic | BindingFlags.Instance);
                 mi.Invoke(helper, new object[] { args, false });
            }

If you want to also synchronize horizontal scrollbars position, you should subscribe to the HScrollbar.ValueChanged event. The code should be almost the same, except for the last line:

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