避免在Windows窗体闪烁? [英] Avoid Flickering in Windows Forms?

查看:120
本文介绍了避免在Windows窗体闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

双缓冲与组合框的工作。
有没有另一种方法,以避免在Windows窗体闪烁?

Double buffering not working with combo-box. is there any another methods to avoid flickering in windows forms?

我有一个窗户,它的面板数构成。我展示只有一个根据我的菜单选择一个时间面板。

i have one windows form with number of panels in it. I'm showing only one panel at a time based on my menu selection.

我有一个图标面板,一个头板和组合框。基于组合框的gridview1和2填充选定的项目。当我用我的键盘快速选择组合框项向下箭头图标面板和面板标题总是重新绘制。我需要保持这两个没有任何变化。这两个面板生产一些闪动效果(即它们在闪烁或闪烁),而我改变组合框中选定的索引。有什么办法避免这种闪烁?我想双缓冲形式构造函数和窗体加载事件启用。
请帮助..............

i have one icon panel,one header panel and the combo box. based on the selected item of that combo-box the gridview1 and 2 are filling. when I'm rapidly selecting the combo-box item using my keyboard down arrow the icon panel and the header panel are always repainting. i need to keep that both without any change. this two panels producing some flashing effect(ie,they are blinking or flashing) while I'm changing the combo box selected index. is there any way to avoid this flashing.? i tried double-buffered enabled in form constructor and form load event. Please Help..............

InitializeComponent();
                this.SetStyle(ControlStyles.DoubleBuffer, true);
                this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                this.SetStyle(ControlStyles.UserPaint, true);
                this.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
                this.SetStyle(ControlStyles.Opaque, false);
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                this.SetStyle(ControlStyles.ResizeRedraw, true);



我试图在形式上constuctor和形式加载事件

i tried this code in form constuctor and form load event

推荐答案

另一种解决方案:

//TODO: Don't forget to include using System.Runtime.InteropServices.

internal static class NativeWinAPI
{
    internal static readonly int GWL_EXSTYLE = -20;
    internal static readonly int WS_EX_COMPOSITED = 0x02000000;

    [DllImport("user32")]
    internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32")]
    internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
}

和表单的构造函数应该如下所示:

And your form constructor should look as follows:

public MyForm()
{
    InitializeComponent();

    int style = NativeWinAPI.GetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE);
    style |= NativeWinAPI.WS_EX_COMPOSITED;
    NativeWinAPI.SetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE, style);
}

在上面的代码中,你可能会改变这一点。处理来像 MyFlickeringPanel.Handle

In the code above, you might change this.Handle to something like MyFlickeringPanel.Handle

您可以阅读一些关于它在这里:扩展窗口风格在这里: 函数CreateWindowEx

You can read a bit more about it here: Extended Window Styles and here: CreateWindowEx.

通过WS_EX_COMPOSITED组,采用双缓冲窗口的get
底部到顶部画订单的所有后代。底部到顶部
画顺序允许后代窗口具有半透明(阿尔法)
和透明度(色键)的影响,但只有当后代
窗口还具有WS_EX_TRANSPARENT位集。双缓冲允许
窗口及其后代,以无闪烁涂漆。

With WS_EX_COMPOSITED set, all descendants of a window get bottom-to-top painting order using double-buffering. Bottom-to-top painting order allows a descendent window to have translucency (alpha) and transparency (color-key) effects, but only if the descendent window also has the WS_EX_TRANSPARENT bit set. Double-buffering allows the window and its descendents to be painted without flicker.

这篇关于避免在Windows窗体闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆