微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在System.Windows.Forms.RichTextBox中禁用绘制VScrollbar

我有一个从RichTextBoxinheritance的自定义控件。 该控件具有“禁用”富文本编辑的function。 我通过在TextChanged事件期间将Rtf属性设置为text属性来实现此目的。

这是我的代码是这样的:

private bool lockTextChanged; void RichTextBox_TextChanged(object sender,EventArgs e) { // prevent StackOverflowException if (lockTextChanged) return; // remember current position int rtbstart = rtb.SelectionStart; int len = rtb.SelectionLength; // prevent painting rtb.SuspendLayout(); // set the text property to remove the entire formatting. lockTextChanged = true; rtb.Text = rtb.Text; rtb.Select(rtbstart,len); lockTextChanged = false; rtb.ResumeLayout(true); }

这很好。 然而,在一个像200行的大文本中,控件抖动(你看到了第一行的文字)。

为了防止发生这种情况,我过滤了SuspendLayout()和ResumeLayout()之间的WM_PAINT

一个迷你转储有用的.NETdebugging

Powershell Get-Content + Invoke-Expression单独执行语句,还是一次执行所有语句?

C#中的本地窗口层次结构和类名

在FAXCOMEX LIb的C#实现中System.Runtime.InteropServices.COMException错误

在哪里可以设置Windows XP中CurrentUICulture的初始值?

private bool layoutSuspended; public new void SuspendLayout() { layoutSuspended = true; base.SuspendLayout(); } public new void ResumeLayout() { layoutSuspended = false; base.ResumeLayout(); } public new void ResumeLayout(bool performlayout) { layoutSuspended = false; base.ResumeLayout(performlayout); } private const int WM_PAINT = 0x000F; protected override void WndProc(ref System.Windows.Forms.Message m) { if (!(m.Msg == WM_PAINT && layoutSuspended)) base.WndProc(ref m); }

这个技巧,RichTextBox不会抖动anymoe。

这就是我想要的,除了一件事情:

每当我input文本到我的控制滚动条仍然抖动。

现在我的问题:有没有人有我的线索如何防止在挂起/恢复布局过程中重新绘制滚动条?

从C#应用程序获取WindowsExplorer中的当前select?

Windows桌面交换机/工具栏

将应用程序依赖项部署到程序文件夹或GAC中

Windows应用程序安装在哪里+ .NET + VS2005

如何在VB.NET中切换Caps Lock?

SuspendLayout()不会产生效果,RTB中没有需要安排的子控件。 RTB缺少大多数控件所具有的Begin / EndUpdate()方法,虽然它支持它。 它暂停绘画,虽然我不确定它暂停滚动条的更新。 添加如下:

public void BeginUpdate() { SendMessage(this.Handle,WM_SETREDRAW,(IntPtr)0,IntPtr.Zero); } public void EndUpdate() { SendMessage(this.Handle,(IntPtr)1,IntPtr.Zero); } // P/invoke declarations private const int WM_SETREDRAW = 0xb; [System.Runtime.InteropServices.DllImport("user32.dll")] private extern static IntPtr SendMessage(IntPtr hWnd,int msg,IntPtr wp,IntPtr lp);

防止用户编辑文本的更好方法是将ReadOnly属性设置为True。 通过覆盖CreateParams也可以完全移除滚动条。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐