Windows窗体中图像资源的本地化 [英] Localization of image resources in Windows Forms

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

问题描述

我正在使用C#3.5和解释了整个事情。以下是我从中获取的一个示例,其中显示了如何从资源中检索本地化图像:

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


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

When I'm adding a resource image (for example, a JPEG file), I can use the resource manager to get 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.

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).

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.

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...)...

解决方案

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 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.

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");

这篇关于Windows窗体中图像资源的本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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