Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
sudipta biswas 19-Jun-13 5:35am    
Didn't get what do you mean by unlimited dynamic control?. Let say you need to create n number of button in a form.
loop from 1 to n
Button b=new Button();
b.Text= Text in the languge you want.
Then add the control in your form.

Is that what you want?
Matt T Heffron 19-Jun-13 15:00pm    
Which UI framework are you using: Winforms or WPF or ???
The solution will depend on this.
I have a rather nice solution for WPF, but if you're using winforms it is of no use.

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.
 
Share this answer
 
I think following code will be useful to you...


Default.aspx page

XML
<%@ 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"

C#
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();
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900