none
不知是否为微软的bug或者是限制?可能是限制? RRS feed

  • 问题

  • 源码如下,,将 48改为 49 即崩溃,,
    是否微软讲窗体内控件的嵌套层数限制为49呢? 加上窗体50层?有什么办法可以突破限制么?或者是我的设置有些问题?

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace TestPanel
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                this.Controls.Add(endp);
                doit(endp).Paint+=new PaintEventHandler(PaintPanel);          
            }

            void PaintPanel(object sender, PaintEventArgs e)
            {
                e.Graphics.FillRectangle(Brushes.Black, new Rectangle(10, 10, 50, 50));
            //    throw new NotImplementedException();
            }
            Panel endp = new Panel();
            int i = 0;
            Panel doit(Panel e)
            {
                if (i++ >= 48)
                    return e;
                Panel p = new Panel();
                p.Dock = DockStyle.Fill;
                e.Controls.Add(p);
               
                return doit(p);
            }
        }
    }

    2010年3月9日 14:09

答案

  • 你好!
         Windows对句柄数的确是有限制的,默认情况下单个进程创建的用户句柄不能超过10000,而GDI句柄也不能超过10000,可以通过修改注册表,来修改这个上限,对应的注册表项是:“GDIProcessHandleQuota”与“USERProcessHandleQuota”
         关于嵌套的限制是怎样的,这个我还没有找到官方的说明,我们等等看其他版主有什么高见!
    周雪峰
    • 已建议为答案 mazhou 2010年3月10日 9:34
    • 已标记为答案 KeFang Chen 2010年3月11日 5:59
    2010年3月10日 0:18
    版主

全部回复

  • 我觉得应该是个限制。



    山西.net俱乐部
    2010年3月9日 14:42
    版主
  • 你好!
         Windows对句柄数的确是有限制的,默认情况下单个进程创建的用户句柄不能超过10000,而GDI句柄也不能超过10000,可以通过修改注册表,来修改这个上限,对应的注册表项是:“GDIProcessHandleQuota”与“USERProcessHandleQuota”
         关于嵌套的限制是怎样的,这个我还没有找到官方的说明,我们等等看其他版主有什么高见!
    周雪峰
    • 已建议为答案 mazhou 2010年3月10日 9:34
    • 已标记为答案 KeFang Chen 2010年3月11日 5:59
    2010年3月10日 0:18
    版主
  • 我这儿48就错了,40可以运行,错误提示是:  {"创建窗口句柄时出错。"}

    估计是周版所说的句柄限制
    霸王
    2010年3月10日 7:48
  • 这个问题我之前也回答过,就是因为窗口句柄数限制。

    不过您可以把 Form_Load 中的代码放到 Form_Show 去看看。
    Mark Zhou
    2010年3月10日 9:34