我在 TabControl 中有几个多行文本框。 tabcontrol 有一个滚动条,但是一旦多行文本框获得焦点,滚动就会滚动文本框而不是 tabcontrol。有什么方法可以阻止文本框接收事件并更像普通文本框,但仍然是多行的?
最佳答案
将 TextBox.ScrollBars 属性设置为 Vertical。这为文本框提供了滚动文本的滚动条。确保 TextBox 适合 TabPage,这样您就不会在标签页中看到滚动条。例如,您可以将 TextBox.Dock 属性设置为 Fill。
我猜不是,也许您说的是鼠标滚轮。向您的项目添加一个新类并粘贴如下所示的代码。编译。将工具箱顶部的新控件拖放到窗体上,替换现有的文本框。
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
class MyTextBox : TextBox {
protected override void WndProc(ref Message m) {
// Send WM_MOUSEWHEEL messages to the parent
if (m.Msg == 0x20a) SendMessage(this.Parent.Handle, m.Msg, m.WParam, m.LParam);
else base.WndProc(ref m);
}
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}
关于c# - 阻止 "stealing"滚动事件中的多行 TextBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3124464/