更新在运行时创建的面板的问题。 [英] problem with updating a panel created at runtime.

查看:55
本文介绍了更新在运行时创建的面板的问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有返回面板的方法的类。该面板不是用可视化编辑器创建的,而是用手工编写的 - 因为有些

面板上的内容可以是动态的,因此我选择做这是

的方式。


无论如何,我有一个按钮的事件处理程序,它实例化了一个对象
我提到的类并调用方法返回

面板。我把面板放在form1上就像这样:


//它真的不叫''Class'',我更改了名称以简化

post

Class myClass = new Class();

this.Controls.Add(myClass.getPanel());


到目前为止所做的一切都有效。


如果再次调用该事件处理程序(即n次;超过

一次),由于信息更改并需要显示在自定义面板上的

,运行时的结果是面板看起来不会更新。

我已经设置了一些断点并进行了调试。需要在面板上更新

的信息确实正在更新,因为

调试器中断了。但是当this.Controls.Add(myClass.getPanel());是打电话给
,旧信息仍然在表格上。


我真正迷失的地方是面板的新实例反映了

更新了信息,但是当它被添加到表单中时,只有第一个

的面板实例,带有初始信息,显示为

显示。如何在表单上获得最新的面板?我在考虑删除电话时想到了b / b
但是我不确定在运行时创建面板时是否会运行
。建议是

非常感谢。


谢谢!

I have a class with a method which returns a panel. The panel was not
created with the visual editor, I coded it by hand -- because some of
the content on the panel can be dynamic and thus I chose to do it that
way.

At any rate, I have an event handler for a button which instantiates
an object of that class I mentioned and calls the method to return the
panel. I put the panel on form1 like so:

// it''s really not called ''Class'', I changed the name to simplify the
post
Class myClass = new Class();
this.Controls.Add(myClass.getPanel());

Everything up to this point works.

If that event handler is ever called again (i.e., n times; more than
once), due to information which changed and needs to be displayed on
the custom panel, the result at runtime is the panel doesn''t appear to
update.

I''ve put some breakpoints in and debugged. The information which
needs to be updated on the panel is indeed updating as viewed with the
debugger breaks. But when this.Controls.Add(myClass.getPanel()); is
called, the old information remains on the form.

Where I''m really lost is the new instance of the panel reflects the
updated information but when it''s added to the form, only the first
instance of the panel, with the initial information, is ever
displayed. How can I get the newest panel on the form? I was
thinking about making a call to remove but I''m not sure that would
work when the panel is being created at runtime. Suggestions are
greatly appreciated.

Thanks!

推荐答案

如果你我没有删除面板,你为什么要重新添加它?

你能不能只保留对面板的引用并直接修改它?


6月2日14:25,Adam Sandler< cor ... @ excite.comwrote:
If you''re not removing the panel, why are you trying to re-add it?
Can you not just keep a reference to the panel and modify it directly?

On 2 Jun, 14:25, Adam Sandler <cor...@excite.comwrote:

我有一个类,其方法返回一个面板。该面板不是用可视化编辑器创建的,而是用手工编写的 - 因为有些

面板上的内容可以是动态的,因此我选择做这是

的方式。


无论如何,我有一个按钮的事件处理程序,它实例化了一个对象
我提到的类并调用方法返回

面板。我把面板放在form1上就像这样:


//它真的不叫''Class'',我更改了名称以简化

post

Class myClass = new Class();

this.Controls.Add(myClass.getPanel());


到目前为止所做的一切都有效。


如果再次调用该事件处理程序(即n次;超过

一次),由于信息更改并需要显示在自定义面板上的

,运行时的结果是面板看起来不会更新。

我已经设置了一些断点并进行了调试。需要在面板上更新

的信息确实正在更新,因为

调试器中断了。但是当this.Controls.Add(myClass.getPanel());是打电话给
,旧信息仍然在表格上。


我真正迷失的地方是面板的新实例反映了

更新了信息,但是当它被添加到表单中时,只有第一个

的面板实例,带有初始信息,显示为

显示。如何在表单上获得最新的面板?我在考虑删除电话时想到了b / b
但是我不确定在运行时创建面板时是否会运行
。建议是

非常感谢。


谢谢!
I have a class with a method which returns a panel. The panel was not
created with the visual editor, I coded it by hand -- because some of
the content on the panel can be dynamic and thus I chose to do it that
way.

At any rate, I have an event handler for a button which instantiates
an object of that class I mentioned and calls the method to return the
panel. I put the panel on form1 like so:

// it''s really not called ''Class'', I changed the name to simplify the
post
Class myClass = new Class();
this.Controls.Add(myClass.getPanel());

Everything up to this point works.

If that event handler is ever called again (i.e., n times; more than
once), due to information which changed and needs to be displayed on
the custom panel, the result at runtime is the panel doesn''t appear to
update.

I''ve put some breakpoints in and debugged. The information which
needs to be updated on the panel is indeed updating as viewed with the
debugger breaks. But when this.Controls.Add(myClass.getPanel()); is
called, the old information remains on the form.

Where I''m really lost is the new instance of the panel reflects the
updated information but when it''s added to the form, only the first
instance of the panel, with the initial information, is ever
displayed. How can I get the newest panel on the form? I was
thinking about making a call to remove but I''m not sure that would
work when the panel is being created at runtime. Suggestions are
greatly appreciated.

Thanks!


6月2日下午1:29,ssg31415926< newsjunkm ... @ gmail.comwrote:
On Jun 2, 1:29 pm, ssg31415926 <newsjunkm...@gmail.comwrote:

如果您没有删除面板,为什么要重新添加它?
If you''re not removing the panel, why are you trying to re-add it?



因为面板上的一些对象(标签,richtextbox等)

改变了,我想反映当前的数据。我是否错误地认为
假设尝试将其重新添加到表单中会给我

" refresh"我需要的行为?

Because some of the objects on the panel (labels, richtextboxes, etc)
change and I want to reflect the current data. Have I incorrectly
assumed that trying to re-add it to the form would give me the
"refresh" behavior I need?


您是否正在更新之前添加的面板实例,或者每次创建新面板是否为



面板上有什么?定期控制?或者是定制的油漆?


Marc
Are you updating the panel instance that you previously added, or are
you creating a new panel each time?

And what is on the panel? Regular controls? or is it custom painted?

Marc


这篇关于更新在运行时创建的面板的问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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