如何删除列表框闪烁 [英] How to remove listbox flashing
问题描述
1。运行代码
2.调整大小窗口
观察:
调整大小时列表框闪烁。
如何删除这个闪烁?
Andrus。
使用System;
使用System.Windows .Forms;
使用System.Collections.Generic;
使用System.Drawing;
公共类测试
{
static void Main()
{
Application.Run(new ReportDialogForm());
}
}
类ReportDialogForm:表格
{
public ReportDialogForm()
{
tabControl1 = new TabControl();
tabPage1 = new TabPage();
reportListBox = new ListBox();
tabControl1.Anchor =((AnchorStyles)((((AnchorStyles.Top |
AnchorStyles.Bottom)
| AnchorStyles.Left)
| AnchorStyles.Right)));
tabControl1.Controls.Add(tabPage1);
tabControl1。位置=新点(0,0);
tabControl1.Padding = new Point(0,0);
tabControl1.SelectedIndex = 0;
tabControl1。大小=新大小(591,296);
tabControl1.TabIndex = 0;
tabPage1.Controls.Add(reportListBox);
tabPage1 .Location = new Point(4,29);
tabPage1.Margin = new Padding(0);
tabPage1.Size = new Size(583,263);
tabPage1.TabIndex = 0;
tabPage1.Layout + = new LayoutEventHandler(tabPage1_Layout);
reportListBox.Anchor = AnchorStyles.None;
reportListBox.Size = new Size(287,384);
reportListBox.TabIndex = 1000;
ClientSize = new Size(588,292);
Controls.Add(tabControl1);
for(int i = 0;我< 100; i ++)
reportListBox.Items.Add(" MMMMMMMMMMMMMMMMMMMMMM");
加载+ = new EventHandler(ReportDialogForm_Load);
}
void ReportDialogForm_Load(object sender,EventArgs e)
{
StartPosition = FormStartPosition.Manual;
位置=新点(10,10);
ClientSize =新尺寸(400,400);
}
void tabPage1_Layout(object sender,LayoutEventArgs e)
{
SuspendLayout();
int height = 100;
reportListBox.Top = height;
reportListBox.Height = tabPage1.Height - height;
reportListBox.Width = tabPage1.Width / 2;
reportListBox.Left = 0;
ResumeLayout();
}
TabControl tabControl1;
TabPage tabPage1;
ListBox reportListBox;
}
Andrus写道:
1.运行代码
2.调整大小窗口
观察:
调整大小时列表框闪烁。
如何删除此闪烁?
典型的解决方案是双缓冲。
尝试在表单中设置''DoubleBuffered = true;''的构造函数或其他
初始化事件。
DoubleBuffered是受保护的属性,所以你不能例如设置
列表框的版本。
- Barry
-
< a rel =nofollowhref =http://barrkel.blogspot.com/target =_ blank> http://barrkel.blogspot.com/
Barry,
典型的解决方案是双缓冲。
尝试设置''DoubleBuffered = true;''在你的表单'的构造函数或其他
初始化事件。
DoubleBuffered是受保护的属性,所以你不能例如设置
列表框的版本。
谢谢。
我添加了DoubleBuffered = true;作为构造函数的第一行:
public ReportDialogForm()
{
DoubleBuffered = true;
>
但是,列表框在调整大小时仍然闪烁。
添加Doublebuffered没有任何区别。
Andrus。
>
Andrus写道:
Barry,
A典型的解决方案是双缓冲。
尝试在表单的构造函数或其他
初始化事件中设置''DoubleBuffered = true;''。
DoubleBuffered是受保护的属性,所以你不能这么做设置
列表框的版本。
谢谢。
我添加了DoubleBuffered = true;作为构造函数的第一行:
public ReportDialogForm()
{
DoubleBuffered = true;
抱歉,我没有仔细阅读你的帖子 - 问题实际上是由TabControl引起的
;表格''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' (无论如何)。
有一个新的Windows样式参数可以指定为
CreateWindowEx在Windows XP及更高版本上消除了这种闪烁。您可以通过覆盖表单上的
保护的CreateParams属性来获得.NET以应用此样式(WS_EX_COMPOSITED)。试试这个:
protected override CreateParams CreateParams
{
get
{
CreateParams result = base.CreateParams;
result.ExStyle | = 0x02000000; // WS_EX_COMPOSITED
返回结果;
}
}
这是有效的,因为WS_EX_COMPOSITED强制整个控件(在这种情况下为表格
)在其所有子控件中使用双缓冲。
您可以在此处阅读有关WS_EX_COMPOSITED的更多信息:
http://msdn.microsoft .com / zh-CN / libr ... 80(VS.85).aspx
- Barry
-
http://barrkel.blogspot.com/
1. Run code
2. Resize window
Observed:
Listbox flashes during resize.
How to remove this flashing ?
Andrus.
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Drawing;
public class Test
{
static void Main()
{
Application.Run(new ReportDialogForm());
}
}
class ReportDialogForm : Form
{
public ReportDialogForm()
{
tabControl1 = new TabControl();
tabPage1 = new TabPage();
reportListBox = new ListBox();
tabControl1.Anchor = ((AnchorStyles)((((AnchorStyles.Top |
AnchorStyles.Bottom)
| AnchorStyles.Left)
| AnchorStyles.Right)));
tabControl1.Controls.Add(tabPage1);
tabControl1.Location = new Point(0, 0);
tabControl1.Padding = new Point(0, 0);
tabControl1.SelectedIndex = 0;
tabControl1.Size = new Size(591, 296);
tabControl1.TabIndex = 0;
tabPage1.Controls.Add(reportListBox);
tabPage1.Location = new Point(4, 29);
tabPage1.Margin = new Padding(0);
tabPage1.Size = new Size(583, 263);
tabPage1.TabIndex = 0;
tabPage1.Layout += new LayoutEventHandler(tabPage1_Layout);
reportListBox.Anchor = AnchorStyles.None;
reportListBox.Size = new Size(287, 384);
reportListBox.TabIndex = 1000;
ClientSize = new Size(588, 292);
Controls.Add(tabControl1);
for (int i = 0; i < 100; i++)
reportListBox.Items.Add( "MMMMMMMMMMMMMMMMMMMMMM");
Load += new EventHandler(ReportDialogForm_Load);
}
void ReportDialogForm_Load(object sender, EventArgs e)
{
StartPosition = FormStartPosition.Manual;
Location = new Point(10, 10);
ClientSize = new Size(400, 400);
}
void tabPage1_Layout(object sender, LayoutEventArgs e)
{
SuspendLayout();
int height = 100;
reportListBox.Top = height;
reportListBox.Height = tabPage1.Height - height;
reportListBox.Width = tabPage1.Width / 2;
reportListBox.Left = 0;
ResumeLayout();
}
TabControl tabControl1;
TabPage tabPage1;
ListBox reportListBox;
}
Andrus wrote:
1. Run code
2. Resize window
Observed:
Listbox flashes during resize.
How to remove this flashing ?A typical solution for this is double buffering.
Try setting ''DoubleBuffered = true;'' in your form''s constructor or other
initialization event.
DoubleBuffered is a protected property, so you can''t e.g. set the
listbox''s version.
-- Barry
--
http://barrkel.blogspot.com/
Barry,
A typical solution for this is double buffering.
Try setting ''DoubleBuffered = true;'' in your form''s constructor or other
initialization event.
DoubleBuffered is a protected property, so you can''t e.g. set the
listbox''s version.thank you.
I added DoubleBuffered = true; as first line in constructor:
public ReportDialogForm()
{
DoubleBuffered = true;
However, listbox still blinks on resize.
Adding Doublebuffered did not make any difference.
Andrus.
Andrus wrote:
Barry,
A typical solution for this is double buffering.
Try setting ''DoubleBuffered = true;'' in your form''s constructor or other
initialization event.
DoubleBuffered is a protected property, so you can''t e.g. set the
listbox''s version.
thank you.
I added DoubleBuffered = true; as first line in constructor:
public ReportDialogForm()
{
DoubleBuffered = true;Sorry, I didn''t read your post closely enough - the problem is actually
caused by the TabControl; the form''s DoubleBuffered won''t help you
(actually, the form''s DoubleBuffered would have only affected drawing on
the form directly, not child controls, in any case).
There is a new-ish Windows style parameter that can be specified to
CreateWindowEx that eliminated this flicker on Windows XP and up. You
can get .NET to apply this style (WS_EX_COMPOSITED) by overriding the
protected CreateParams property on your form. Try this:
protected override CreateParams CreateParams
{
get
{
CreateParams result = base.CreateParams;
result.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
return result;
}
}
This works because WS_EX_COMPOSITED forces the whole control (the form
in this case) to use double-buffering throughout all its child controls.
You can read more about WS_EX_COMPOSITED here:
http://msdn.microsoft.com/en-us/libr...80(VS.85).aspx
-- Barry
--
http://barrkel.blogspot.com/
这篇关于如何删除列表框闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!