用 Visual Studio 開發 WinForm 的視窗程式介面時,專案有很方便的方式開發多語系介面。
但是,如果是在程式啟動、載入之後,才要變更語系呢?
在網路上搜尋、嘗試了一陣子,還沒找到方便的方法,只能刻苦耐勞地去刻:
用 Visual Studio 開發 WinForm 的視窗程式介面時,專案有很方便的方式開發多語系介面。
但是,如果是在程式啟動、載入之後,才要變更語系呢?
在網路上搜尋、嘗試了一陣子,還沒找到方便的方法,只能刻苦耐勞地去刻:
System.Windows.Forms.WebBrowser
在前端寫 JavaScript code 辨別。
//alert( window.navigator.appName ); // Edge, 11 -> "Netscape"==appName
engine = null;
if ( window.navigator.appName == "Microsoft Internet Explorer" || window.navigator.appName == "Netscape" )
{
// This is an IE browser. What mode is the engine in?
if ( document.documentMode ) // IE8 or later
{
engine = document.documentMode;
}
else // IE 5-7
{
engine = 5; // Assume quirks mode unless proven otherwise
if ( document.compatMode )
{
if ( document.compatMode == "CSS1Compat" )
engine = 7; // standards mode
}
// There is no test for IE6 standards mode because that mode
// was replaced by IE7 standards mode; there is no emulation.
}
// the engine variable now contains the document compatibility mode.
//alert( engine ); // 10, 9, 8, ...
}
參考來源:Internet
繼上一篇:[程式][WinForm][C#] backgroundWorker執行緒 如何修改WinForm主執行緒上控制元件的值?
使用 System.Windows.Forms.MethodInvoker 跨執行緒 修改主執行緒的值;
但「public delegate void MethodInvoker();」不能傳參數進去。
取得 WebBrowser的cookie:
string cookieStr = webBrowser.Document.Cookie;
存到 CookieContainer:
private CookieContainer GetCookieContainer( string cookieStr )
{
CookieContainer myCookieContainer = new CookieContainer();
string[] cookstr = cookieStr.Split( ';' );
foreach ( string str in cookstr )
{
string[] cookieNameValue = str.Split( '=' );
Cookie ck = new Cookie( cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().ToString() );
ck.Domain = Properties.Settings.Default.ServerDomain ; // 必須寫對.
myCookieContainer.Add( ck );
}
return myCookieContainer;
}
使用 HttpWebRequest:
以 TextBox 為例:
private void bgw1_DoWork(object sender, DoWorkEventArgs e)
{
{
this.Invoke(new MethodInvoker(delegate { textBox1.Text = "working.." }));
}
}
參考:Textbox text from background worker?