多语言C#桌面应用程序 [英] Multilanguage C# desktop application

查看:78
本文介绍了多语言C#桌面应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#桌面应用程序中更改动态创建控件的语言。



例如 - 在我的应用程序中,我必须动态创建大量按钮。我可以更改预定义控件的语言,但如何更改无限动态按钮的语言。

How can i change language for dynamically create controls in c# desktop application.

For example - in my application i have to create lot of buttons dynamically. I can change language for predefined controls but how to change language for unlimited dynamic button.

推荐答案

当您的软件动态创建按钮时,它必须有关于什么的信息文本应该显示在该按钮上。

当某些用户更改语言设置时,该信息仍然可用。因此,使用相同的算法查找给定语言和控件组合的匹配文本。
At the moment your software creates the button dynamically, it must have information on what text should be displayed on that button.
The information should still be available when some user changes the language setting. So use the same algorithm to find the matching text for a given combination of language and control.


我认为以下代码对您有用...





Default.aspx页



I think following code will be useful to you...


Default.aspx page

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblWelcome" runat="server" meta:resourcekey="lblWelcomeResource1"

            Text="Welcome to Learning"></asp:Label>
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem Value="en-us">English</asp:ListItem>
            <asp:ListItem Value="hi-in">हिंदी</asp:ListItem>
        </asp:DropDownList><br />
        <br />
        <asp:Label ID="lblNotice" runat="server" meta:resourcekey="lblNoticeResource1" Text="Today is:"></asp:Label>&nbsp;
        <asp:Label ID="lblTime" runat="server" meta:resourcekey="lblTimeResource1"></asp:Label></div>
    </form>
</body>
</html>







Default.aspx.cs






"Default.aspx.cs"

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblTime.Text = DateTime.Now.ToShortDateString();
    }

    protected override void InitializeCulture()
    {
        if (Request.Form["DropDownList1"] != null)
        {
            UICulture = Request.Form["DropDownList1"];
            Culture = Request.Form["DropDownList1"];
        }
        base.InitializeCulture();
    }
}


这篇关于多语言C#桌面应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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