在的WinForms定位图像资源 [英] localization image resources in winforms

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

问题描述

我使用C#3.5和WinForms(Telerik的和如果它事项)。
我怎样才能得到一个按钮,使用3种不同的图片(一个用于空闲的,一个是鼠标悬停和一个同时点击)三个(或N ..)不同的语言。

I'm using C# 3.5 and winforms (and telerik if it matters). How can I get a button to use 3 different pictures (one for idle, one for mouse hover and one for while clicked) in three (or N..) different languages.

当我加入一个资源的图像(例如,jpg文件)
我可以用资源管理器toget它,一切都很好。
我还可以添加其他图像​​(,而使用不同的名称的),然后更改文件的语言和改变图片。

When I'm adding a resource image (for example, a jpg file) I can use resource manager toget it and everything is great. I can also add another image (while using a different name) and then change the language of the file and change the picture.

现在的问题是:
如何更改按钮图像中的每个语言正确的形象,如果我不能给他们同样的名称(例如,在A.JPG resource.resx,A.JPG资源-foo.resx等)。

Now the question: How can I change the button image in each language to the correct image if I can't give them the same name (e.g. a.jpg in resource.resx, a.jpg in resources-foo.resx etc).

我不认为这是现实中的code当前区域性来检查,然后通过使用图像资源的名字在OnMouseEnter在/叶/下实现三个画面之间的切换。

I don't think it is realistic to check in the code the current culture and then by using the pictures resources names in the OnMouseEnter/Leaves/Down implement the switch between the three picture.

作为一个普通的应用程序有100多个按钮,必须有一个简单易用的方式做到这一点,我只是想不出(或查找...)...

As an average application has 100+ buttons there must be a simple and easy way to do it, that I just can't think of (or find...)...

推荐答案

ResourceManager的在.NET不只做本地化字符串。它可以提供任何种类,包括图像的局部二进制内容。这意味着你将永远需要编写逻辑来选择一个图像的相关本地化的版本,甚至不会需要处理的图像文件的路径。你刚才问的ResourceManager给你你想要的形象,它会给你这个形象的相应语言版本(取决于电流的UICulture )。

The ResourceManager in .NET does not only do string localization. It can provide localized binary content of any kind, including images. This means that you will never need to write logic to pick the relevant localized version of an image, and won't even need to manipulate image file paths. You just ask the ResourceManager to give you the image you want, and it will give you the appropriate language version of this image (depending on the current UICulture).

Visual Studio中可以很容易地添加图像资源文件。资源编辑器在左上角的按钮(见下文),让您查看不同类型的包含在您的resx文件的资源,它可以是字符串(最常见的选择,我们大多数人都熟悉),图像和更多。

Visual Studio makes it easy to add images to a resource file. The Resource editor has a button in the top left corner (see below) that lets you view the different types of resources contained in your resx file, which can be strings (the most common choice that most of us are familiar with), images and more.

MSDN链接解释整个东西。下面是我从花了一个例子,显示了如何从资源检索本地化图片:

This MSDN link explain the whole thing. Here's one example I took from it which shows how to retrieve a localized image from your resources:

rm = new ResourceManager("Images", this.GetType().Assembly);
pictureBox1.Image = (System.Drawing.Image)rm.GetObject("flag");

这篇关于在的WinForms定位图像资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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