Delphi Prism:如何加载Winform而不显示它?
我有一个 winform,需要在显示之前加载它来更新其控件的值或属性。
我发现一个 stackoverflow 问题问了同样的事情,但它的答案并没有真正帮助我。 加载表单而不显示
任何示例代码将不胜感激。谢谢你,
I have a winform that needs to be loaded to update its controls' values or properties, before it is to be shown.
I found a stackoverflow question asking the same thing, but it's answer doesn't really help me. Load a form without showing it
Any sample code will be appreciated. Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需创建表单的新实例并设置控件的值。
检查此代码
顺便记住,如果您想修改或访问另一个表单的控件,您必须设置控件的属性
Modifiers
以访问public
。Only you need create a new instance of the form and set the values of the controls.
check this code
Btw remember if you want modify or access the controls of another form you must set the property
Modifiers
of the control to access topublic
.创建这样的表单:
假设您已经在
MyForm
上实现了一个方法来更新值,请调用它:以通常的方式显示表单:
Create the form like this:
Assuming you have implemented a method on
MyForm
to update the values, call it:Show the form in the usual way:
来自 MSDN:
因此,您可以在此事件处理程序中显示表单之前对控件进行所有必要的更新。
但实际上,使用数据绑定可能更好 在控件上,以便它们自动反映您希望它们显示的当前值,并且您不必编写任何粘合代码,将数据带入控件(并从控件中读取数据)。
From MSDN:
So you can do all updates to the controls that are necessary before you show the form in this event handler.
But actually it is probably better to use databinding on the controls, so that they automatically reflect the current values you want them to show and you don't have to write any glue code bringing data on controls (and reading from them).