我用增加Label的方式画了很多方块(因为需要相应事件,没有用画图的办法).
然后函数每次开始的时候,用Controls.Clear+Dispose的方式来清理资源.
这个画图的函数执行很多次后(随机,大概是画了几千个label后),再画出的Label会出现红叉.
然后任何窗体都打不开了,包括程序的和windows的,连任务管理器也打不开.
错误日志记录如下
Error creating window handle. System.Windows.Forms at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)大家帮帮忙,保守需求是我想在出现红叉后,可以让用户按一个按钮,然后清理下资源什么的,可以重新开始.
谢谢了
然后函数每次开始的时候,用Controls.Clear+Dispose的方式来清理资源.
这个画图的函数执行很多次后(随机,大概是画了几千个label后),再画出的Label会出现红叉.
然后任何窗体都打不开了,包括程序的和windows的,连任务管理器也打不开.
错误日志记录如下
Error creating window handle. System.Windows.Forms at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)大家帮帮忙,保守需求是我想在出现红叉后,可以让用户按一个按钮,然后清理下资源什么的,可以重新开始.
谢谢了
你可以用dataGridView, 然后用cell的事件啊。
几千个控件, 几千个handle, 别的不算, 光这个就够系统受的了。没有解决方案。
或者说解决方案就是不要用那么多的控件。 用一个DataGridView之类的, 一个handle一堆显示的控件。
用Label的事件,无非是点击事件么。
根据鼠标点击的位置,来处理事件。
其实每次只产生几十个个label,我估计这个动作多做很多次后,以前的handle没有清空
自己画的话,你首先要定义一个数据结构,来记录"label"的位置。
在画板的鼠标事件中,按x,y坐标,判断触发数据结构中哪个"label"的事件。
定义好结构,写个共同方法,会发现一切都很简单。PS:现在出问题一定是label没有很好的释放,可以检查一下释放的代码。
{
base.Dispose(true);
}
我在每个自定义控件里都这样写的,然后确保都调用了
总之信息不足,问题不好找。
rectangle.contains()这个方法可以判断一个point或rectangle是否在此矩形中
你用LABEL太浪费资源了,一个控件就是一个窗口