在vb.net中的非ui线程上向流面板添加多个控件? [英] Adding multiple controls into flow panel on non-ui thread in vb.net?

查看:75
本文介绍了在vb.net中的非ui线程上向流面板添加多个控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我想一次将多个用户控件添加到流面板中,而不会让用户界面冻结,我已经尝试从后台工作程序添加控件,但是因为它可以'不能添加它而得到错误不会改变父控制或类似的东西,任何帮助都会受到赞赏。

解决方案

你将不得不创建一个委托给为你添加控件,如下所示:



**假设您的流量控制称为流量

 私有 委托  sub  delAddControl(ctrl  as  Control)
private sub AddControl(ctrl as Control)
if (flow.InvokeRequired)然后
dim d as new delAddControl( AddressOf AddControl)
me .Invoke(d,ctrl)
else
flow.Controls.Add(ctrl)
end 如果
end sub





我已经用C#编写了这段代码100次但是我的vb有点生疏所以我确定这不会编译但你应该能够看看我在做什么,让你的工作从那里开始。





****编辑*****

哦,是的,那么你可以从你的BackgroundWorker调用AddControl,控件将被添加到你的UI而不会锁定它,因为在BackgroundWorker中正在完成繁重的工作。

Okay, I want to add multiple user controls into a flow panel at one time without the UI freezing, I''ve tried adding the controls from a Background Worker but get an error about how it cannot be added because it can''t change parent control or something like that, any help would be appreciated.

解决方案

You are going to have to create a delegate to add the controls for you, something like this:

** assuming your flow control is called ''flow''

private delegate sub delAddControl(ctrl as Control)
private sub AddControl(ctrl as Control)
    if (flow.InvokeRequired) then
        dim d as new delAddControl(AddressOf AddControl)
        me.Invoke(d, ctrl)
    else
        flow.Controls.Add(ctrl)
    end if
end sub



I have written this code 100 times in C# but my vb is a little rusty so im sure this wont compile but you should be able to see what im doing and get yours working from that.


**** EDIT *****
Oh Yea, then you can just call AddControl from your BackgroundWorker and the controls will get added to your UI without locking it up because the heavy lifting is being done in the BackgroundWorker.


这篇关于在vb.net中的非ui线程上向流面板添加多个控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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