显然,这仍然是一个痛苦的屁股...但没有像重置控件的属性那么多。 我做的另一件事是我已经停止设置我想在设计师中更改的属性。相反,我在Form_Load中手动设置它们。 还有一件事可能会有所帮助,但我无法确认(似乎有一段时间有所帮助,但随后我发现它没有帮助的实例是确保在命名空间级别定义枚举之类的东西,而不是在类内部定义。我知道它没有任何意义,就像我说我发现我仍然失去控制的情况,但它确实似乎暂时缓解了这个问题。 /> 最后,将您打开的VS.net标签(特别是设计师)的数量保持在最低限度。我个人认为它有一些事情要做,VS.net没有按照正确的顺序执行任务,或者没有等待 A在它尝试做之前完成B.保持标签的数量打开 -mdb Hi,I have been developing with C# User Controls and occasionally have a problemwhere I "lose" a control from the design surface of the User Control. Thecontrols that I am using to build my User Controls are themselves customcontrols.Occasionally, when I change something in either the User Control and/or oneof 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 tobe on it is no longer there. But if you look at the code for the UserControl, the custom control object is still declared, and any references toit in code are still there. But apparently it''s no longer added to the UserControl 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 theUser Control3) Set any custom control properties that were set before, and re-registerfor custom control events (because the eventhandler methods are still thereall I have to do is select the right one thank goodness)Still, this is an ENORMOUS PAIN IN THE BUTT when it happens. Can somebodytell me how to avoid this situation (Please don''t say don''t use customcontrols on User Controls).Thanks.BBM 解决方案Yeah this seems to be a problem in the design of VS.net - lots of otherpeople have seen similar behavior. I have noticed that it only happensAFTER a compile (or more precisely, when the DLL has changed and thusneeds to be reloaded and the controls re-rendered to include anychanges), when you switch to the designer for that page. In otherwords, if you have the designer and the code view open, and you arelooking at the code view when you compile, it MIGHT happen (and willONLY happen) when you switch to the design view.What that means for me (and you, if you want to adopt this method) isthat 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 haveVS.net configured to automatically save the files before a compile (isthat even an option? i can''t remember.) I have a fairly large andcomplex project that I use this method on and its not too bad - as longas you notice when it happens.Obviously, this is still a pain-in-the-butt... but not as much ashaving to reset the properties of the control.The other thing that I do is that I''ve stopped setting the propertiesthat I want to change in the designer. Instead, I set them manually inthe Form_Load.One more thing that might help but which I can''t confirm (it seemed tohelp for a while but then I found instances where it didn''t help) is tomake sure that things like enums are defined at the namespace level, andnot inside of classes. I know it doesn''t make any sense, and like Isaid I''ve found instances where I still lost my controls, but it sureseemed to alleviate the problem for a time.And finally, keep the number of VS.net tabs (especially designers) thatyou have open to a minimum. I personally think it has something to dowith VS.net not performing things in the right order, or not waiting forA to finish before it tries to do B. Keeping the number of tabs openseems to help for me - that is, it reduces how often the problem occurs.-mdb 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 这篇关于"失去"用户控件控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!