"失去"用户控件控件 [英] "Losing" Controls on User Controls

查看:79
本文介绍了"失去"用户控件控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我一直在使用C#用户控件进行开发,偶尔会遇到问题

我在哪里丢失来自用户控件的设计表面的控件。用于构建我的用户控件的

控件本身是自定义的

控件。


偶尔,当我改变某些东西时当我转到

Visual时,在用户控件和/或其中的一个自定义控件上重新编译一个

。用户控件的设计表面,用于

的自定义控件不再存在。但是如果你查看User

Control的代码,仍然会声明自定义控件对象,并且代码中对它的任何引用仍然存在。但显然它不再添加到用户

控制代码。


我有一个解决方法...

)删除丢失的声明来自用户控制代码的对象。

2)进入工具箱并获取自定义控件并将其重新放回

用户控件

3)设置之前设置的任何自定义控件属性,并为自定义控件事件重新注册

(因为事件处理程序方法仍在那里

我所要做的就是选择合适的一个谢天谢地)


然而,当它发生时,这是一个非常痛苦的痛苦。可以有人

告诉我如何避免这种情况(请不要说不要在用户控件上使用自定义

控件)。


谢谢。


BBM

解决方案




猜猜..你确定你不会手动编辑

表格或用户控件的初始化方法吗?如果你这样做可能会导致错误

,因为你不允许这样做但是如果你不...这是一些什么

奇怪的再次我没有理由说不要使用自定义控件

另一个用户控制它不能是错误..


Nirosh。


" BBM" < bb*@bbmcompany.com>在留言中写道

news:13 ********************************** @ microsof t.com ...



我一直在使用C#用户控件进行开发,偶尔会出现
问题,我失去了来自用户控件的设计表面的控件。我用来构建用户控件的
控件本身就是自定义的
控件。

偶尔,当我在用户控件和/或
中更改某些内容时当我转到
Visual时,它上面的一个自定义控件并重新编译。用户控件的设计表面,使用
的自定义控件不再存在。但是如果查看User
Control的代码,仍会声明自定义控件对象,并且代码中的任何引用
仍然存在。但显然它已不再添加到代码中的
用户控件中。

我有一个解决方法......
1)删除丢失的声明来自用户控制代码的对象。
2)进入工具箱并获取自定义控件并将其重新放回
用户控件上。
3)设置之前设置的任何自定义控件属性,和
重新注册自定义控件事件(因为事件处理程序方法仍然是
我所要做的就是选择合适的一个感谢良好)

仍然,这是一个当它发生时,它会发出巨大的痛苦。有人可以告诉我如何避免这种情况(请不要说不要在用户控件上使用自定义
控件)。

谢谢。

BBM



=?Utf-8?B?QkJN?=< bb *@bbmcompany.com>写在

新闻:13 ********************************** @ microsof t .com:

偶尔,当我在用户控件和/或其中一个自定义控件上更改某些内容并重新编译时,当我转到"视觉"用户控件的设计表面,以前的自定义
控件不再存在。但是,如果您查看用户控件的代码,则仍会声明自定义控件对象,并且代码中对它的任何引用仍然存在。但是显然它已经不再添加到代码中的用户控件中了。




是的,这似乎是VS.net设计中的一个问题 - 许多其他人已经看到了类似的行为。我注意到它只在编译后发生了

(或者更准确地说,当DLL发生变化时因此需要重新加载$ ​​b $ b并且控件重新呈现为包含当您切换到该页面的设计器时,任何

更改)。在其他

字样中,如果您打开设计器和代码视图,并且在编译时查看代码视图,那么可能会发生(并且会<当你切换到设计视图时,只需要发生



这对我来说意味着什么(如果你想采用这种方法,那么你的意思是)

当它发生时,只需退出VS.net环境并重新启动它。

一切都应该恢复原样,只要你有

VS.net配置为在编译之前自动保存文件(

即使是一个选项?我也记不起来。)我有一个相当大的

复杂的项目,我使用这个方法,并且它不是太糟糕 - 只要你注意到它发生的时候就是




显然,这仍然是一个痛苦的屁股...但没有那么多,b $ b不得不重置控件的属性。


另一件事我我做的是我已经停止设置财产了ies

我想在设计师中改变。相反,我手动将它们设置在

的Form_Load中。


还有一件事可能会有所帮助,但我无法确认(似乎是

帮助了一段时间然后我找到了它没有帮助的实例)

确保在命名空间级别定义枚举之类的内容,并且

不在课堂内。我知道这没有任何意义,就像我说的那样我已经找到了我仍然丢失控件的情况,但确定

似乎减轻了一段时间的问题。


最后,保持开放的VS.net标签(特别是设计师)的数量最少。我个人认为它有事情要做

,VS.net没有以正确的顺序执行任务,或者没有等待

A在它尝试做B之前完成。保持标签数量打开

似乎对我有帮助 - 也就是说,它减少了问题发生的频率。


-mdb


我在设计winforms时遇到了这个问题。我的所有usercontrols

都处于单独的程序集中。如果我在设计视图中打开了一个表单,并且我是编辑用户控件的
,那么尝试编译用户控件并且它失败,

控件从中删除形式,但仍然宣布。基本上我的

解决方法是从来没有。我在设计视图中打开一个表单,当我更改我的用户控件时使用

usercontrol。这对我有用。


-

Lateralus [MCAD]

" BBM" < bb*@bbmcompany.com>在留言中写道

新闻:E4 ********************************** @ microsof t.com ...

mdb,

感谢您提供非常完整和有帮助的回复。

我对某些人感到内疚你提到的东西:在课堂上宣布枚举,

倾向于在设计师中打开太多的标签。

我喜欢你的解决方法比我的好。<你认为微软的任何人都在努力吗?

感谢你的帮助。

BBM

" MDB"写道:

=?Utf-8?B?QkJN?=< bb *@bbmcompany.com>在
新闻中写道:13 ********************************** @ microsof t.com:< blockquote class =post_quotes>>偶尔,当我在用户控件中更改某些内容时
>和/或其中一个自定义控件并重新编译,当我
>转到视觉用户控件的设计表面,定制
>曾经在它上面的控制不再存在。但如果你看看
>用户控件的代码,自定义控件对象仍然是
>声明,代码中对它的任何引用仍然存在。但是
>显然它已经不再添加到代码中的用户控件中了。



是的,这似乎是VS.net设计中的一个问题 - 很多其他的
人看到过类似的行为。我注意到它只发生在编译之后(或者更确切地说,当DLL发生变化并因此需要重新加载并且控件重新渲染以包含任何更改时),当您切换到该页面的设计器时。换句话说,如果您打开设计器和代码视图,并且在编译时查看代码视图,那么可能会发生(并且只会发生)切换到设计视图。

这对我来说意味着什么(以及你,如果你想采用这种方法),当它发生时,只需退出VS.net环境并重新启动只要你有VS.net配置为在编译之前自动保存文件(即使是一个选项?我可以),一切都应该按照它的方式回来请记住。我有一个相当庞大且复杂的项目,我使用这种方法,并且它不会太糟糕 - 只要你发现它就会发现它。
显然,这仍然是一个痛苦的屁股...但没有像重置控件的属性那么多。

我做的另一件事是我已经停止设置我想在设计师中更改的属性。相反,我在Form_Load中手动设置它们。

还有一件事可能会有所帮助,但我无法确认(似乎
有一段时间有所帮助,但随后我发现它没有帮助的实例是确保在命名空间级别定义枚举之类的东西,而不是在类内部定义。我知道它没有任何意义,就像我说我发现我仍然失去控制的情况,但它确实似乎暂时缓解了这个问题。 />
最后,将您打开的VS.net标签(特别是设计师)的数量保持在最低限度。我个人认为它有一些事情要做,VS.net没有按照正确的顺序执行任务,或者没有等待
A在它尝试做之前完成B.保持标签的数量打开
-mdb



Hi,

I have been developing with C# User Controls and occasionally have a problem
where I "lose" a control from the design surface of the User Control. The
controls that I am using to build my User Controls are themselves custom
controls.

Occasionally, when I change something in either the User Control and/or one
of the custom controls that are on it and recompile, when I go to the
"Visual" design surface of the User Control, the custom control that used to
be on it is no longer there. But if you look at the code for the User
Control, the custom control object is still declared, and any references to
it in code are still there. But apparently it''s no longer added to the User
Control in code.

I have a workaround...
1) Remove declaration of the "lost" object from the User Control code.
2) Go into the toolbox and get the custom control and put it back on the
User Control
3) Set any custom control properties that were set before, and re-register
for custom control events (because the eventhandler methods are still there
all I have to do is select the right one thank goodness)

Still, this is an ENORMOUS PAIN IN THE BUTT when it happens. Can somebody
tell me how to avoid this situation (Please don''t say don''t use custom
controls on User Controls).

Thanks.

BBM

解决方案

Hi,

One guess.. are you sure that you don''t edit the Initializer method of the
form or the user control manually??? if you do so that may cause the error
since you are not allow to do so but If you don''t.. this is some what
strange and again i don''t see a reason to say not to use custom control on
another user control it cannot be the error..

Nirosh.

"BBM" <bb*@bbmcompany.com> wrote in message
news:13**********************************@microsof t.com...

Hi,

I have been developing with C# User Controls and occasionally have a problem where I "lose" a control from the design surface of the User Control. The
controls that I am using to build my User Controls are themselves custom
controls.

Occasionally, when I change something in either the User Control and/or one of the custom controls that are on it and recompile, when I go to the
"Visual" design surface of the User Control, the custom control that used to be on it is no longer there. But if you look at the code for the User
Control, the custom control object is still declared, and any references to it in code are still there. But apparently it''s no longer added to the User Control in code.

I have a workaround...
1) Remove declaration of the "lost" object from the User Control code.
2) Go into the toolbox and get the custom control and put it back on the
User Control
3) Set any custom control properties that were set before, and re-register for custom control events (because the eventhandler methods are still there all I have to do is select the right one thank goodness)

Still, this is an ENORMOUS PAIN IN THE BUTT when it happens. Can somebody
tell me how to avoid this situation (Please don''t say don''t use custom
controls on User Controls).

Thanks.

BBM



=?Utf-8?B?QkJN?= <bb*@bbmcompany.com> wrote in
news:13**********************************@microsof t.com:

Occasionally, when I change something in either the User Control
and/or one of the custom controls that are on it and recompile, when I
go to the "Visual" design surface of the User Control, the custom
control that used to be on it is no longer there. But if you look at
the code for the User Control, the custom control object is still
declared, and any references to it in code are still there. But
apparently it''s no longer added to the User Control in code.



Yeah this seems to be a problem in the design of VS.net - lots of other
people have seen similar behavior. I have noticed that it only happens
AFTER a compile (or more precisely, when the DLL has changed and thus
needs to be reloaded and the controls re-rendered to include any
changes), when you switch to the designer for that page. In other
words, if you have the designer and the code view open, and you are
looking at the code view when you compile, it MIGHT happen (and will
ONLY happen) when you switch to the design view.

What that means for me (and you, if you want to adopt this method) is
that when it happens, just exit the VS.net environment and restart it.
Everything should come back just the way it was, as long as you have
VS.net configured to automatically save the files before a compile (is
that even an option? i can''t remember.) I have a fairly large and
complex project that I use this method on and its not too bad - as long
as you notice when it happens.

Obviously, this is still a pain-in-the-butt... but not as much as
having to reset the properties of the control.

The other thing that I do is that I''ve stopped setting the properties
that I want to change in the designer. Instead, I set them manually in
the Form_Load.

One more thing that might help but which I can''t confirm (it seemed to
help for a while but then I found instances where it didn''t help) is to
make sure that things like enums are defined at the namespace level, and
not inside of classes. I know it doesn''t make any sense, and like I
said I''ve found instances where I still lost my controls, but it sure
seemed to alleviate the problem for a time.

And finally, keep the number of VS.net tabs (especially designers) that
you have open to a minimum. I personally think it has something to do
with VS.net not performing things in the right order, or not waiting for
A to finish before it tries to do B. Keeping the number of tabs open
seems to help for me - that is, it reduces how often the problem occurs.

-mdb


I''ve run into this problem when designing winforms. All of my "usercontrols"
are in a seperate assembly. If I have a form open in design view, and I''m
editing a usercontrol, then attempt to compile the usercontrol and it fails,
the control is removed from the form, but is still declared. Essentially my
workaround is to "NEVER" have a form open in design view that is using a
usercontrol when I''m making changes to my usercontrols. This works for me.

--
Lateralus [MCAD]
"BBM" <bb*@bbmcompany.com> wrote in message
news:E4**********************************@microsof t.com...

mdb,

Thanks for a very complete and helpful response.

I''m guilty of some of the stuff you mention: declaring enums in classes,
and
tending to have way too many tabs open in the designer.

I like your workaround a lot better than mine too.

Do you think anybody at Microsoft is working on this?

Thanks for your help.

BBM

"mdb" wrote:

=?Utf-8?B?QkJN?= <bb*@bbmcompany.com> wrote in
news:13**********************************@microsof t.com:

> Occasionally, when I change something in either the User Control
> and/or one of the custom controls that are on it and recompile, when I
> go to the "Visual" design surface of the User Control, the custom
> control that used to be on it is no longer there. But if you look at
> the code for the User Control, the custom control object is still
> declared, and any references to it in code are still there. But
> apparently it''s no longer added to the User Control in code.



Yeah this seems to be a problem in the design of VS.net - lots of other
people have seen similar behavior. I have noticed that it only happens
AFTER a compile (or more precisely, when the DLL has changed and thus
needs to be reloaded and the controls re-rendered to include any
changes), when you switch to the designer for that page. In other
words, if you have the designer and the code view open, and you are
looking at the code view when you compile, it MIGHT happen (and will
ONLY happen) when you switch to the design view.

What that means for me (and you, if you want to adopt this method) is
that when it happens, just exit the VS.net environment and restart it.
Everything should come back just the way it was, as long as you have
VS.net configured to automatically save the files before a compile (is
that even an option? i can''t remember.) I have a fairly large and
complex project that I use this method on and its not too bad - as long
as you notice when it happens.

Obviously, this is still a pain-in-the-butt... but not as much as
having to reset the properties of the control.

The other thing that I do is that I''ve stopped setting the properties
that I want to change in the designer. Instead, I set them manually in
the Form_Load.

One more thing that might help but which I can''t confirm (it seemed to
help for a while but then I found instances where it didn''t help) is to
make sure that things like enums are defined at the namespace level, and
not inside of classes. I know it doesn''t make any sense, and like I
said I''ve found instances where I still lost my controls, but it sure
seemed to alleviate the problem for a time.

And finally, keep the number of VS.net tabs (especially designers) that
you have open to a minimum. I personally think it has something to do
with VS.net not performing things in the right order, or not waiting for
A to finish before it tries to do B. Keeping the number of tabs open
seems to help for me - that is, it reduces how often the problem occurs.

-mdb



这篇关于&QUOT;失去&QUOT;用户控件控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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