编辑Winforms中使用的图像而无需关闭VS [英] Edit Image used in Winforms without closing VS

查看:65
本文介绍了编辑Winforms中使用的图像而无需关闭VS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像应用于Visual Studio中的控件(在本例中为PictureBox,但它可以是Button或任意数量的其他控件).我想在第3方程序中编辑此图像,但是VS在打开文件时不会允许任何其他程序访问该文件.即使我暂时将图形更改为其他图形,以便不再使用要保存的图像,VS仍然不会放弃对该文件的控制.

因此,每次我要进行更改时,我必须关闭整个项目以将文件保存在其他程序中,然后启动它并重新加载该项目.不用说,这非常耗时,我希望能够在VS运行时编辑程序中使用的图形,而不是每次都关闭并重新加载.

(我不需要运行该项目-我不希望在运行时更改该项目.但是至少应该可以在不完全关闭VS的情况下换出图形...)

解决方案

问题摘要:
修改WinForm控件的基础Image源文件后,允许自动更新Visual Studio表单设计器界面.

问题已报告:
使用位图文件分配控件的图像"属性时,GDI +会锁定该文件,从而阻碍了对源文件的任何修改尝试.

可以克服以下问题,将图像作为

注释:
-将位图文件添加到VS资源时,将保留原始位图格式.
-确认位图资源的 Persistece 属性设置为在编译时链接.

可能的问题/缺点.
有时,资源缓存可能会出现问题:当试图将资源图像应用于控件的Image属性时,资源图像似乎卡在了位图文件的较早/先前版本中.
图像资源或文件没有任何更改似乎可以解决此问题.

当项目"运行时,将显示正确的图像,但设计时的图像外观不会改变(是错误的"图像).

这只是资源索引问题.
如果您尝试在调试模式下尝试修改基础Image的控件,或者将Image从Project Resources中删除,然后再次添加并修改,则可能会发生这种情况.

要解决此问题:

  • 关闭受影响的解决方案/项目(和Visual Studio实例).
  • 删除 ../Bin/Debug 目录中的所有构建文件(.exe文件,其关联的.pdb文件和exe.config文件).
  • 删除 ../Obj/Debug 目录中的所有文件.
    可以删除这些文件而不会影响应用程序功能.
  • 重新打开解决方案/项目并清理/重建.

这将重置缓存,并且设计时表单界面将使用相应的图片进行更新.
.

I have an image applied to a control in Visual Studio (in this case a PictureBox, but it could be a Button or any number of other controls). I would like to edit this image in a 3rd party program, but VS will not let any other program access the file while it is open. Even if I temporarily change the graphic to something else so that the image I want to save is no longer being used, VS will still not relinquish control of the file.

So instead I have to shut down the entire project in order to save the file in the other program, then start it up and reload the project, every time I want to make a change. Needless to say, this is very time-consuming and I would prefer to be able to edit the graphics used in the program while VS is running instead of shutting it down and reloading every time.

(I don't need the project to be running - I wouldn't expect that to be changeable at runtime. But it should at least be possible to swap out graphics without completely shutting down VS...)

解决方案

Question summary:
Allowing the automatic update of Visual Studio form designer interface after a WinForm Control's underlying Image source file has been modified.

Problem reported:
When the Control's Image property is assigned using a Bitmap file, GDI+ locks the file, thus hindering any modification attempt to the source file.

This problem can be overcome loading the images as Project Resources.

  • Store your Bitmap files inside the default Project Resources folder.
    This directory is automatically created as soon as an Image file is added to a Project through the Project Properties → Resources → Images, but it can be created manually.
  • Assign the image from a Resource Image.
    When the Image is assigned this way, the Bitmap file will not be locked.
  • When the underlying Bitmap file is edited (with an external graphics program or using the built-in editor), Visual Studio will update a Control's Image as soon as it acknowledge the modification.
    This usually happens in real-time.

Notes:
- When adding a Bitmap file to VS Resource, the original Bitmap format is preserved.
- Verify that the Persistece property of the Bitmap resource is set to Linked at compile time.

Possible problems/drawbacks.
Occasionally, an issue with resource caching may arise: the resource Image, when trying to apply it to a Control's Image property, appears to be stuck to an older/previous version of the Bitmap file.
No change to the Image resource or file seems to correct the problem.

When the the Project is Run, the correct image is shown, but the design-time Image appearance doesn't change (is the "wrong" one).

This is just a resource indexing issue.
It may happen, mostly, if you try to modify a control underlying Image while in debug mode or the Image is removed from the Project Resources and then added again, modified.

To solve the problem:

  • Close the affected Solution/Project (and the Visual Studio instance).
  • Delete all build file in the ../Bin/Debug directory (the .exe file, its associated .pdb file and the exe.config file).
  • Delete all files in the ../Obj/Debug directory.
    These files can be deleted without affecting the application functionality.
  • Re-open the Solution/Project and Clean/Rebuild.

This will reset the cache and the Design-Time form interface will be updated with the corrent Images.
.

这篇关于编辑Winforms中使用的图像而无需关闭VS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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