2013-07-22 5 views
0

메시지 상자에 사용자가 선택한 언어에 따라 정보를 표시하고 싶습니다. lanugage button click에 따라 모든 버튼과 라벨 텍스트를 변경합니다. 하지만이 언어 버튼 클릭을 기반으로 다른 정보를 표시하도록 내 메시지 상자를 만들려면 어떻게해야합니까? 예를 들어, 다른 버튼이 있고 그것을 클릭하면 적절한 메시지 상자가 표시됩니다.이 메시지 상자를 다른 언어로 다른 언어로 표시하고 싶습니다. 내 모든 텍스트가 리소스에 있습니다. 벨로우가 제 코드예요.C# 다국어 메시지 함

private void btnLngEnglish_Click(object sender, EventArgs e) 
    { 
     CultureInfo ci = new CultureInfo("en-US"); 
     Assembly a = Assembly.Load("read_display"); 
     ResourceManager rm = new ResourceManager("read_display.language.languageRes", a); 
     button7.Text = rm.GetString("file", ci); 
     button4.Text = rm.GetString("timecount", ci); 
     button6.Text = rm.GetString("daterange", ci); 
     button3.Text = rm.GetString("specdate", ci); 
     button1.Text = rm.GetString("phrasesearch", ci); 
     button5.Text = rm.GetString("higherval", ci); 
     label3.Text = rm.GetString("langsel", ci); 
     label5.Text = rm.GetString("rowcount", ci); 
     label4.Text = rm.GetString("timeElapsed", ci); 
     label1.Text = rm.GetString("filterdate", ci); 
     label2.Text = rm.GetString("hide", ci); 
    } 

    private void btnLangPolish_Click(object sender, EventArgs e) 
    { 
     CultureInfo ci = new CultureInfo("pl-PL"); 
     Assembly a = Assembly.Load("read_display"); 
     ResourceManager rm = new ResourceManager("read_display.language.languageResPL", a); 
     button7.Text = rm.GetString("file", ci); 
     button4.Text = rm.GetString("timecount", ci); 
     button6.Text = rm.GetString("daterange", ci); 
     button3.Text = rm.GetString("specdate", ci); 
     button1.Text = rm.GetString("phrasesearch", ci); 
     button5.Text = rm.GetString("higherval", ci); 
     label3.Text = rm.GetString("langsel", ci); 
     label5.Text = rm.GetString("rowcount", ci); 
     label4.Text = rm.GetString("timeElapsed", ci); 
     label1.Text = rm.GetString("filterdate", ci); 
     label2.Text = rm.GetString("hide", ci); 
    } 

편집 : 모든

private void button1_Click(object sender, EventArgs e) 
    { 
     string searchString = textBox8.Text; 
     if (String.IsNullOrEmpty(textBox8.Text)) 
     { 
      //Here I would like to diplay messages in two different language, based on previous language button click. Can I do it?? 
      MessageBox.Show("Enter value to filter"); 
     } 
     else 
     { 
      bool found = false; 
      foreach (DataGridViewRow row in dataGridView1.Rows) 
      { 
       if (row.Cells[1].Value.ToString().Contains(searchString)) 
       { 
        row.DefaultCellStyle.BackColor = System.Drawing.Color.MediumPurple; 
        row.Selected = true; 
        found = true; 
       } 
       if (row.Cells[2].Value.ToString().Contains(searchString)) 
       { 
        row.DefaultCellStyle.BackColor = System.Drawing.Color.MediumPurple; 
        found = true; 
       } 
      } 
      if (!found) 
      { 
       //Here I would like to do same thing 
       MessageBox.Show("Value was not found"); 
      } 
     } 
    } 
+0

은 내가 이런 식으로 그것을 할 수 있다고 생각 자원 – Sandy

답변

1

첫째, 나는 그들이 실제로 무엇을 반영하기 위해 모든 버튼의 이름을 변경할 것입니다. 이것은 더 많은 충고입니다.

어느 쪽이든, MessageBox.Show(rm.GetString("messageboxData", ci))으로 전화 할 수 없습니까?

EDIT1은 (주석 참조)

class MyClass 
{ 
    CultureInfo currentCultureInfo; 
    public MyClass() 
    { 
     //defaulting to en-US 
     currentCultureInfo = new CultureInfo("en-US"); 
    } 

    public void SetLanguageToEnglish() 
    { 
     currentCultureInfo = new CultureInfo("en-US"); 
    } 

    public void SetLanguageToItalian() 
    { 
     currentCultureInfo = new CultureInfo("it-IT"); 
    } 

    public string GetTranslation(string s) 
    { 
     //By the way, you should to the same to 'a' and 'rm', since they don't need to be instantiated each time. But I'll use your code to avoid confusion. 
     Assembly a = Assembly.Load("read_display"); 
     ResourceManager rm = new ResourceManager("read_display.language.languageRes", a); 
     return rm.GetString(s, currentCultureInfo); 
    } 
} 
+0

에서 메시지를 옮겨보십시오 : 내가 무엇을 의미의 라인에 무언가이다. 이 두 버튼은 내 앱의 언어를 변경하기 위해 사용됩니다. 내가 그들을 클릭하면 메인 페이지에 표시된 모든 버튼과 라벨이 한 언어에서 다른 언어로 바뀝니다. 이 메시지 상자를 변경하려는 위치를 정확하게 표시하도록 코드를 편집합니다. – user2592968

+0

잠깐, 이해할 것 같아. CultureInfo에 대한 전역 참조 (예 : currentCultureInfo)를 저장할 수 있습니다.이 참조는 버튼 클릭 이벤트 내에 설정됩니다. 그런 다음 rm.GetString ("messageboxData", currentCultureInfo)을 호출하여 외부에서 데이터에 액세스 할 수 있습니다. – KappaG3

+0

예제를 보여주기 위해 내 게시물을 편집했습니다. – KappaG3