在处理资源时,Visual Studio不好. [英] Visual Studio is no good when handling resources...

查看:96
本文介绍了在处理资源时,Visual Studio不好.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好专家,

VS糟糕的资源处理能力使我深受打击.
这不是第一次...

我在该项目的Resources.resx文件上有一些图像,这些图像被用作菜单,工具栏等的图标.
我已删除其中一张图片,以将其替换为另一张图片.
然后我切换回我的设计师,以设置新图像.

那就是所有的地狱都崩溃了!
我的工具栏上的项目不见了!菜单不见了!
甚至状态栏项目!走了!
它们是在设计器生成的代码中声明的,但是似乎删除了SomeControl.AddRange(...)之类的行!

正如我所说,这不是第一次发生.
我以前使用的解决方案包括手动重新添加设计器生成的行以及类似的其他丑陋内容.

将来如何解决该问题,以及如何恢复控件?

Hello experts,

I''ve been badly hit by VS''s poor handling of resources.
And this is not the first time...

I had some images on the project''s Resources.resx file, which were used as icons for menus, toolbars, etc.
I''ve removed one of the images in order to replace it with another.
Then I switched back to my designer, in order to set the new image.

And that''s when all hell broke loose!
My toolbar''s items were gone! Menu''s were gone!
Even status bar items! GONE!
They are declared in the designer generated code, but it appears that lines like SomeControl.AddRange(...) were erased!

As I said, that''s not the first time it happend.
Previous solutions I used involved manually re-adding designer generated lines, and other ugly stuff like that.

How do I overcome the problem in the future, and how can I restore my controls?

推荐答案

我不熟悉您遇到的特定问题,但是如果您尝试保留设计器生成的代码,我有个建议.假设您正在使用C#,则可以创建部分类(即,在多个文件中定义的类).您可以将所需的设计器生成的代码放入设计器希望不会接触的自己文件中.
I''m not familiar with the specific problem you are having, but if you are trying to keep designer generated code, I have a suggestion. Assuming you are working with C#, you can create partial classes (i.e., a class that is defined in multiple files). You can take the designer generated code you want and put it into your own file that the designer will hopefully not touch.


简短的答案是从不手动编辑此代码文件.

在设计器代码文件中记录以下警告:
The short answer is never manually edit this file.

Take note of the following warning in your designer code file:
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>


每当您更改表单布局中的任何内容时,都会重新创建此文件,因此,除非您通过设计器进行了修改,否则您所做的任何手动更改都可能会丢失.


This file is recreated any time you change anything in the layout of your form so unless you have modified it through the designer any manual changes you make will probably be lost.


另一种简单的添加方法图像是,只需将它们添加到您的项目中,就像您将添加任何其他文件并将其构建操作设置为Embedded Resource一样.

为了使用它,您只需获取一个位图对象
Another simple way to add images is, simply add them to your project as you will add any other file and set their build action to Embedded Resource.

And in order to use it you can simply get a bitmap object
Bitmap bitmap = new Bitmap (GetType (), "SomeImage.bmp");



希望这可以帮助您避免在某种程度上处理资源文件.



Hope this would help you to avoid handling Resource files upto some extent.


这篇关于在处理资源时,Visual Studio不好.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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