在 richTextBox 中选择文本时禁用滚动 (C#)

发布于 2024-12-06 04:13:34 字数 302 浏览 4 评论 0原文

我有一个包含(很多)文本的富文本框。我为其添加了一个搜索选项,当用户按下搜索按钮时,程序将所有匹配项标记为黄色(通过对每个选择执行选择BackColor),然后选择第一个匹配项。 结果是程序看起来像是“扫描”文本,然后选择第一个匹配项。 我不希望发生这种情况,因此我需要禁用特定代码段的自动滚动(在执行 Select() 时发生)。 我在发布之前搜索了这个问题,我发现的主要主题涉及附加文本,但这不是我的情况。 知道如何解决我的问题吗?

我使用 .NET Framework 4 (Visual Studio 2010) 并用 C# 编写。

提前致谢, 盖伊

I have a rich text box that contains (a lot of) text. I've added a search option for it, and when the user presses the search button, the program marks all the matches in yellow (by performing selectionBackColor on each selection) and then selects the first match.
The result is that the program looks like it "scans" the text and then selects the first match.
I don't want this to happen so I need to disable the autoscrolling (that occurs when performing Select()) for a specific code segment.
I searched this problem before posting and the main topics I found involved appending text, and that's not my case.
Any idea of how to solve my problem?

I'm using .NET framework 4 (visual studio 2010) and I write in C#.

Thanks in advance,
Guy

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

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

发布评论

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

评论(1

疯狂的代价 2024-12-13 04:13:34

好吧,看来我会回答我自己的问题 - 我所要做的就是将这两行与另一个类的属性放在一起:

[DllImport("user32.dll", EntryPoint = "LockWindowUpdate", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LockWindow(IntPtr Handle);

并在开头用 this 包围所需的代码段:

LockWindow(this.Handle);

在末尾用 this 包围:

LockWindow(IntPtr.Zero);

Well it seems that I'll answer my own question - all I had to do was to put these two lines among with the other class's properties:

[DllImport("user32.dll", EntryPoint = "LockWindowUpdate", SetLastError = true, CharSet = CharSet.Auto)]
private static extern IntPtr LockWindow(IntPtr Handle);

and surround the desired code segment with this at the start:

LockWindow(this.Handle);

and this at the end:

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