TableLayoutPanel中非常缓慢响应事件 [英] TableLayoutPanel responds very slowly to events

查看:2242
本文介绍了TableLayoutPanel中非常缓慢响应事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序确实需要放置大量的控件(标签,文本框,domainupdown)在一个不错的订单。于是我继续使用了一些嵌套 TableLayoutPanel中。现在的问题是,这种形式的响应速度很慢大多数事件(调整大小,最大化,最小化和...),它需要真正的长达5秒的表格中,控制得到调整,以redrawed形式的新的大小。

In my application I really needed to place a lot of controls (label, textbox, domainupdown) in a nice order. So I went ahead and used some nested TableLayoutPanel. The problem now is, this form responds very slow to most of events (resize, maximize, minimize and ...) it takes really up to 5 seconds for controls within the tables to get resized, redrawed to the new size of form.

我把一个手指在我的眼睛吧!如果这个形式是慢我的家用电脑(I7 @ 4GHz的和良好的图形卡)上它会做的明天在工作时的老P4电脑上?

I am putting a finger in my eye now! If this form is that slow on my home PC (i7@4GHz and a good graphic card) what it will do tommorow on the old P4 computer at work?

我甚至尝试使用下面的代码,但它absoloutly什么都不做,如果没有减缓下来等着您!

I even tried to use the code below but it does absoloutly nothing, if it is not slowing it down more!

private void FilterForm_ResizeBegin(object sender, EventArgs e)
{
    foreach(TableLayoutPanel tlp in panelFilters.Controls)
    {
        if(tlp != null)
        {
            tlp.SuspendLayout();
        }
    }
}

private void FilterForm_ResizeEnd(object sender, EventArgs e)
{
    foreach (TableLayoutPanel tlp in panelFilters.Controls)
    {
        if (tlp != null)
        {
            tlp.ResumeLayout();
        }
    }
}

请让我知道,如果有一招,使TableLayoutPanel中的工作速度更快...或者,如果你知道一个更好的办法放下有关良好的对齐控制百名。

Please let me know if there is a trick to make tablelayoutpanel to work faster...or if you know a better approach to lay down about hundred of controls nicely aligned.

推荐答案

使用此代码

public class CoTableLayoutPanel : TableLayoutPanel
{
    protected override void OnCreateControl()
    {
        base.OnCreateControl();
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.CacheText, true);
    }

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= NativeMethods.WS_EX_COMPOSITED;
            return cp;
        }
    }

    public void BeginUpdate()
    {
        NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);
    }

    public void EndUpdate()
    {
        NativeMethods.SendMessage(this.Handle, NativeMethods.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);
        Parent.Invalidate(true);
    }
}

public static class NativeMethods
{
    public static int WM_SETREDRAW = 0x000B; //uint WM_SETREDRAW
    public static int WS_EX_COMPOSITED = 0x02000000; 


    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); //UInt32 Msg
}

这篇关于TableLayoutPanel中非常缓慢响应事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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