C# 如何防止文本框闪烁?
我试图阻止文本框闪烁,但迄今为止没有成功。C# 如何防止文本框闪烁?,c#,winforms,textbox,flicker,doublebuffered,C#,Winforms,Textbox,Flicker,Doublebuffered,我试图阻止文本框闪烁,但迄今为止没有成功。 文本框为多行只读 此代码每秒运行几次。文本大约有10k个字符 int ss = txt.SelectionStart; int sl = txt.SelectionLength; txt.Text = s; txt.SelectionStart = ss; txt.SelectionLength = sl; 重新归档问题为我提供了以下可能的解决方案 -但没有一个成功 1) 锁窗口更新 [System.Runtime.InteropServices.D
文本框为多行只读 此代码每秒运行几次。文本大约有10k个字符
int ss = txt.SelectionStart;
int sl = txt.SelectionLength;
txt.Text = s;
txt.SelectionStart = ss;
txt.SelectionLength = sl;
重新归档问题为我提供了以下可能的解决方案-但没有一个成功 1) 锁窗口更新
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool LockWindowUpdate(IntPtr hWndLock);
//...
LockWindowUpdate(txt.Handle);
txt.Text = someText;
LockWindowUpdate(IntPtr.Zero);
2) 固定方式
3) SuspendLayout/ResumeLayout(我猜这与绘画无关,只是一次尝试)
原来父窗体的
CreateParams
必须使用以下标志:
****这是一种完美的方式。**有一个支持IP地址处理的本机Win32控件
public class IPTextBox : TextBox
{
public IPTextBox() : base()
{
}
protected override CreateParams CreateParams
{
get
{
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
CreateParams cp = base.CreateParams;
cp.ClassName = "SysIPAddress32";
return cp;
}
}
}
为什么你一开始就有闪烁?设置文本属性不应导致任何闪烁。你在做什么?问题是什么?我唯一一次看到闪烁是在你对文本框进行一些小更新时。如果这就是您正在做的,也许您应该使用StringBuilder对它们进行批处理?对不起,这个问题并不意味着输入IP地址。那将是一种特殊情况。这一切都是关于一个普通文本框的闪烁。
txt.SuspendLayout();
txt.Text = s;
txt.ResumeLayout();
protected override CreateParams CreateParams {
get {
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
return cp;
}
}
public class IPTextBox : TextBox
{
public IPTextBox() : base()
{
}
protected override CreateParams CreateParams
{
get
{
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
CreateParams cp = base.CreateParams;
cp.ClassName = "SysIPAddress32";
return cp;
}
}
}