2014-12-09 4 views
1

WinForms (C#) 응용 프로그램에서 언어 메뉴 스트립과 사운드 버튼을 만들었지 만 전환 할 수있는 방법을 모르겠습니다.하나의 버튼에 여러 액션이 있습니다.

나는 소리를 멈추고 싶을 때 & 소리가 나면 소리를 멈추고 다시 소리가 나고 아이콘을 바꾼다. 마찬가지로, 언어 메뉴, "Localizable"을 사용하여 언어를 변경하고 처음에 다른 언어로 텍스트를 변경 한 다음 다시 두 번째로 돌아서는 방법은 무엇입니까?

using System.Globalization; 

using System.Threading; 

namespace Project 
{ 
    public partial class Form2 : Form 
    {} 

      private void Menu_LanguageSwitch_Click (object sender, EventArgs e) 
      { 
      //Switch to EN - what's here? 
      { 
       CultureInfo ci = new CultureInfo("en-US"); 
       System.Threading.Thread.CurrentThread.CurrentCulture = ci; 
       System.Threading.Thread.CurrentThread.CurrentUICulture = ci; 

       System.ComponentModel.ComponentResourceManager res = new ComponentResourceManager(typeof(Form2)); 
       res.ApplyResources(lbl_Status, "lbl_Status"); 

       Menu_LanguageSwitch.Text = "Francais"; 
      } 

      //Switch to French 
      { 
       CultureInfo ci = new CultureInfo("fr"); 
       System.Threading.Thread.CurrentThread.CurrentCulture = ci; 
       System.Threading.Thread.CurrentThread.CurrentUICulture = ci; 

       System.ComponentModel.ComponentResourceManager res = new ComponentResourceManager(typeof(Form2)); 

       res.ApplyResources(Menu_LanguageSwitch, "Menu_LanguageSwitch"); 
       res.ApplyResources(label2, "label2"); 
       res.ApplyResources(label3, "label3"); 
       res.ApplyResources(label4, "label4"); 
       res.ApplyResources(label5, "label5"); 
       res.ApplyResources(label6, "label6"); 
       res.ApplyResources(label7, "label7"); 
       res.ApplyResources(label8, "label8"); 
       res.ApplyResources(lbl_Status, "lbl_Status"); 
       Menu_LanguageSwitch.Text = "Francais"; 
      } 
     } 
} 

감사합니다, 초보자에 분명히 확인하십시오 :

여기 내 코드입니다. 저는 신참입니다.

+0

StackOverflow에 오신 것을 환영합니다! [해당 제목에 "태그에"태그를 포함해야합니까? "] (http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-the-titles)를 참조하십시오. 여기서 컨센서스는 다음과 같습니다. "아니, 그들은해서는 안된다". –

답변

0

간단한 방법은 양식 범위 변수를 사용하는 것입니다. 양식에 외부화 CultureInfo ci = new CultureInfo ("fr"); 버튼을 클릭하면 활성 CutureInfo를 확인한 다음 올바른 것으로 바꿉니다

2

버튼을 누를 때 확인할 수 있도록 프로그램의 현재 상태를 추적해야합니다. 간단한 플래그를 들어 ("소리"와 같은)이 단지 부울 될 수 있습니다 지역화 논리는 유사하다

private bool isMuted = false; 

private void onSoundClick(...) 
{ 
    if (isMuted) 
    { 
     //Do unmute kind of things 
     isMuted = false; 
    } 
    else 
    { 
     //Do mute kind of things 
     isMuted = true; 
    } 
} 

,하지만 당신이 2 개 이상의 언어가 되길 원한다면, 당신은을 순환해야합니다 목록/대기열.

관련 문제