visual studio 2010 - C# Multilanguage messagebox -
i messagebox show information according language slected user. change button , label text according lanugage button click. how can make messagebox display different info based on language button click? example if have button , when click it, proper messagebox displayed, messagebox displayed in different languages different user choice. have text in resource. bellow code.
private void btnlngenglish_click(object sender, eventargs e) { cultureinfo ci = new cultureinfo("en-us"); assembly = 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 = 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); }
edit:
private void button1_click(object sender, eventargs e) { string searchstring = textbox8.text; if (string.isnullorempty(textbox8.text)) { //here diplay messages in 2 different language, based on previous language button click. can it?? messagebox.show("enter value 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 same thing messagebox.show("value not found"); } } }
first of all, i'd change names of buttons reflect are. more piece of advice.
either way, can't call messagebox.show(rm.getstring("messageboxdata", ci))
?
edit1 (see comments): mean on lines of:
class myclass { cultureinfo currentcultureinfo; public myclass() { //defaulting 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 way, should same 'a' , 'rm', since don't need instantiated each time. i'll use code avoid confusion. assembly = assembly.load("read_display"); resourcemanager rm = new resourcemanager("read_display.language.languageres", a); return rm.getstring(s, currentcultureinfo); } }
Comments
Post a Comment