程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 三、VB.NET 多語言版本的開發之From窗體調用

三、VB.NET 多語言版本的開發之From窗體調用

編輯:.NET實例教程

frmlogin窗體


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

Namespace MuchLanguagenamespace MuchLanguage
{
    /// <summary>
    /// Form1 的摘要說明。
    /// </summary>
    public Class Frmloginclass Frmlogin : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Label lblusername;
        private System.Windows.Forms.Label lblpassWord;
        private System.Windows.Forms.Label lbllanguage;
        private System.Windows.Forms.Button btnlogon;
        private System.Windows.Forms.Button btncancel;
        private System.Windows.Forms.Button btnchagepwd;
        private System.Windows.Forms.ComboBox CbxSelectLanguage;
        private System.Windows.Forms.TextBox TxtUsername;
        private System.Windows.Forms.TextBox TxtPasswrod;
        private System.Windows.Forms.GroupBox gBox;

        ReadDefaultLanguage Rdla=new ReadDefaultLanguage();
        private string DefaultLanguage;
        private System.Windows.Forms.LinkLabel llblSetLanguageDefine;

        /// <summary>
        /// 必需的設計器變量。
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Frmlogin()
        {
            //
            // Windows 窗體設計器支持所必需的
            //
            InitializeComponent();

            //
            // TODO: 在 InitializeComponent 調用後添加任何構造函數代碼
            //
        }

        /// <summary>
        /// 清理所有正在使用的資源。
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        Windows 窗體設計器生成的代碼#region Windows 窗體設計器生成的代碼
        /// <summary>
        /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
        /// 此方法的內容。
        /// </summary>
        private void InitializeComponent()
        {
            this.lblusername = new System.Windows.Forms.Label();
            this.lblpassWord = new System.Windows.Forms.Label();
            this.lbllanguage = new System.Windows.Forms.Label();
            this.btnlogon = new System.Windows.Forms.Button();
            this.btncancel = new System.Windows.Forms.Button();
            this.btnchagepwd = new System.Windows.Forms.Button();
            this.TxtUsername = new System.Windows.Forms.TextBox();
            this.TxtPasswrod = new System.Windows.Forms.TextBox();
            this.CbxSelectLanguage = new System.Windows.Forms.ComboBox();
            this.llblSetLanguageDefine = new System.Windows.Forms.LinkLabel();
            this.gBox = new System.Windows.Forms.GroupBox();
            this.gBox.SuspendLayout();
            this.SuspendLayout();
            // 
            // lblusername
            // 
            this.lblusername.Location = new System.Drawing.Point(32, 24);
            this.lblusername.Name = "lblusername";
            this.lblusername.Size = new System.Drawing.Size(72, 23);
            this.lblusername.TabIndex = 0;
            this.lblusername.Text = "用戶名:";
            this.lblusername.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lblpassWord
            // 
            this.lblpassWord.Location = new System.Drawing.Point(32, 64);
            this.lblpassword.Name = "lblpassWord";
            this.lblpassWord.Size = new System.Drawing.Size(72, 23);
            this.lblpassWord.TabIndex = 1;
            this.lblpassWord.Text = "密  碼:";
            this.lblpassWord.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lbllanguage
            // 
            this.lbllanguage.Location = new System.Drawing.Point(32, 104);
            this.lbllanguage.Name = "lbllanguage";
            this.lbllanguage.Size = new System.Drawing.Size(72, 24);
            this.lbllanguage.TabIndex = 2;
            this.lbllanguage.Text = "語  言:";
            this.lbllanguage.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // btnlogon
            // 
            this.btnlogon.Location = new System.Drawing.Point(40, 152);
            this.btnlogon.Name = "btnlogon";
            this.btnlogon.Size = new System.Drawing.Size(68, 24);
            this.btnlogon.TabIndex = 2;
            this.btnlogon.Text = "登陸";
            this.btnlogon.Click += new System.EventHandler(this.btnlogon_Click);
            // 
            // btncancel
            // 
            this.btncancel.Location = new System.Drawing.Point(112, 152);
            this.btncancel.Name = "btncancel";
            this.btncancel.Size = new System.Drawing.Size(68, 24);
            this.btncancel.TabIndex = 3;
            this.btncancel.Text = "退出";
            this.btncancel.Click += new System.EventHandler(this.btncancel_Click);
            // 
            // btnchagepwd
            // 
            this.btnchagepwd.Location = new System.Drawing.Point(184, 152);
            this.btnchagepwd.Name = "btnchagepwd";
            this.btnchagepwd.Size = new System.Drawing.Size(114, 24);
            this.btnchagepwd.TabIndex = 4;
            this.btnchagepwd.Text = "更改密碼";
            this.btnchagepwd.Click += new System.EventHandler(this.btnchagepwd_Click);
            // 
            // TxtUsername
            // 
            this.TxtUsername.Location = new&nbs.Drawing.Point(110, 24);
            this.TxtUsername.Name = "TxtUsername";
            this.TxtUsername.Size = new System.Drawing.Size(178, 21);
            this.TxtUsername.TabIndex = 0;
            this.TxtUsername.Text = "";
            // 
            // TxtPasswrod
            // 
            this.TxtPasswrod.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.TxtPasswrod.Location = new System.Drawing.Point(110, 64);
            this.TxtPasswrod.Name = "TxtPasswrod";
            this.TxtPasswrod.PassWordChar = ''*'';
            this.TxtPasswrod.Size = new System.Drawing.Size(178, 21);
            this.TxtPasswrod.TabIndex = 1;
            this.TxtPasswrod.Text = "";
            // 
            // CbxSelectLanguage
            // 
            this.CbxSelectLanguage.Enabled = false;
            this.CbxSelectLanguage.Location = new System.Drawing.Point(110, 107);
            this.CbxSelectLanguage.Name = "CbxSelectLanguage";
            this.CbxSelectLanguage.Size = new System.Drawing.Size(178, 20);
            this.CbxSelectLanguage.TabIndex = 8;
            // 
            // llblSetLanguageDefine
            // 
            this.llblSetLanguageDefine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
&nb          this.llblSetLanguageDefine.Location = new System.Drawing.Point(8, 193);
            this.llblSetLanguageDefine.Name = "llblSetLanguageDefine";
            this.llblSetLanguageDefine.Size = new System.Drawing.Size(296, 20);
            this.llblSetLanguageDefine.TabIndex = 9;
            this.llblSetLanguageDefine.TabStop = true;
            this.llblSetLanguageDefine.Text = "單擊設置默認語言";
            this.llblSetLanguageDefine.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.llblSetLanguageDefine.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.SetLanguageDefine_LinkClicked);
            // 
            // gBox
            // 
            this.gBox.Controls.Add(this.llblSetLanguageDefine);
            this.gBox.Location = new System.Drawing.Point(8, -2);
            this.gBox.Name = "gBox";
            this.gBox.Size = new System.Drawing.Size(312, 216);
            this.gBox.TabIndex = 10;
            this.gBox.TabStop = false;
            // 
            // Frmlogin
            // 
            this.AcceptButton = this.btnlogon;
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClIEntSize = new System.Drawing.Size(330, 223);
            this.Controls.Add(this.CbxSelectLanguage);
            this.Controls.Add(this.TxtPasswrod);
            this.Controls.Add(this.TxtUsername);
            this.Controlsthis.btnchagepwd);
            this.Controls.Add(this.btncancel);
            this.Controls.Add(this.btnlogon);
            this.Controls.Add(this.lbllanguage);
            this.Controls.Add(this.lblpassWord);
            this.Controls.Add(this.lblusername);
            this.Controls.Add(this.gBox);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.Name = "Frmlogin";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Frmlogin";
            this.Load += new System.EventHandler(this.FrmLogon_Load);
            this.gBox.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// 應用程序的主入口點。
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new Frmlogin());
        }

        private void FrmLogon_Load(object sender, System.EventArgs e)
        {
            DefaultLanguage=Rdla.ReadDefaultLanguages();
            ReadDefaultLanguage Rdela=new ReadDefaultLanguage();   
            Rdela.getNames(this,DefaultLanguage);

            this.CbxSelectLanguageBinding();            
        }

        private void CbxSelectLanguageBinding()
        {

            ReadAppConfig Racig=new ReadAppConfig();

            this.CbxSelectLanguage.DataSource=Racig.GetLanguageList(DefaultLanguage);
        
            if(Racig.Getfullnamelanguage(DefaultLanguage)!=null)
            {
                this.CbxSelectLanguage.SelectedItem=Racig.Getfullnamelanguage(DefaultLanguage);
            }
            else
            {
                this.btnlogon.Enabled=false;
            }
        }

        private void SetLanguageDefine_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            Form SetLan=new FrmSetLanguage();
            SetLan.ShowDialog();
        }

        private void btnlogon_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show("單擊我了!");
        }

 &nbs  private void btncancel_Click(object sender, System.EventArgs e)
        {
            this.Close();
            Application.Exit();
        }

        private void btnchagepwd_Click(object sender, System.EventArgs e)
        {
            Form Pwdchange=new FrmPassWordChages();
            Pwdchange.ShowDialog();
        }
    }
}
 
frmSetLanguage窗體-設置默認語言


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

Namespace MuchLanguagenamespace MuchLanguage
{
    /// <summary>
    /// SetLanguageOption 的摘要說明。
    /// </summary>
    public Class FrmSetLanguageclass FrmSetLanguage : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button BtnOK;
        private System.Windows.Forms.Button BtnExit;
        private System.Windows.Forms.GroupBox gBox;
        /// <summary>
        /// 必需的設計器變量。
        /// </summary>
        private System.ComponentModel.Container components = null;
        ReadDefaultLanguage Rdla=new ReadDefaultLanguage();
        private string DefaultLanguage;
        private System.Windows.Forms.ListBox Lboxlang;
        private System.Windows.Forms.Label lblSet;
        private System.Windows.Forms.Label lblOKinfo;
        private System.Windows.Forms.Label lblSetinfo;
        private System.Windows.Forms.Label lblOK;
        private string RbtnTxt;
        
        public FrmSetLanguage()
        {
            //
            // Windows 窗體設計器支持所必需的
            //
            InitializeComponent();

            //
            // TODO: 在 InitializeComponent 調用後添加任何構造函數代碼
            //
        }

        /// <summary>
        /// 清理所有正在使用的資源。
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        Windows 窗體設計器生成的代碼#region Windows 窗體設計器生成的代碼
        /// <summary>
        /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
        /// 此方法的內容。
        /// </summary>
        private void InitializeComponent()
        {
            this.gBox = new System.Windows.Forms.GroupBox();
            this.Lboxlang = new System.Windows.Forms.ListBox();
            this.BtnExit = new System.Windows.Forms.Button();
            this.BtnOK = new System.Windows.Forms.Button();
            this.lblOK = new System.Windows.Forms.Label();
            this.lblSet = new System.Windows.Forms.Label();
            this.lblOKinfo = new System.Windows.Forms.Label();
            this.lblSetinfo = new System.Windows.Forms.Label();
            this.gBox.SuspendLayout();
            this.SuspendLayout();
       &nb            // gBox
            // 
            this.gBox.Controls.Add(this.Lboxlang);
            this.gBox.Location = new System.Drawing.Point(8, 0);
            this.gBox.Name = "gBox";
            this.gBox.Size = new System.Drawing.Size(264, 152);
            this.gBox.TabIndex = 0;
            this.gBox.TabStop = false;
            // 
            // Lboxlang
            // 
            this.Lboxlang.ItemHeight = 12;
            this.Lboxlang.Location = new System.Drawing.Point(8, 16);
            this.Lboxlang.Name = "Lboxlang";
            this.Lboxlang.Size = new System.Drawing.Size(248, 124);
            this.Lboxlang.TabIndex = 0;
            this.Lboxlang.SelectedIndexChanged += new System.EventHandler(this.Lboxlang_SelectedIndExchanged);
            // 
            // BtnExit
            // 
            this.BtnExit.Location = new System.Drawing.Point(160, 163);
            this.BtnExit.Name = "BtnExit";
            this.BtnExit.Size = new System.Drawing.Size(72, 24);
            this.BtnExit.TabIndex = 4;
            this.BtnExit.Text = "返回";
            this.BtnExit.Click += new System.EventHandler(this.BtnExit_Click);
            // 
            // BtnOK
            // 
            this.BtnOK.Location = new System.Drawing.Point(32, 163);
            this.BtnOK.Name = "BtnOK";
            this.BtnOK.TabIndex = 3;
            this.BtnOK.Text = "確定";
            this.BtnOK.Click += new System.EventHandler(this.BtnOK_Click);
            // 
            // lblOK
            // 
            this.lblOK.Location = new System.Drawing.Point(120, 160);
            this.lblOK.Name = "lblOK";
            this.lblOK.Size = new System.Drawing.Size(16, 23);
            this.lblOK.TabIndex = 5;
            this.lblOK.Text = "lblOK";
            this.lblOK.Visible = false;
            // 
            // lblSet
            // 
            this.lblSet.Location = new System.Drawing.Point(152, 160);
            this.lblSet.Name = "lblSet";
            this.lblSet.Size = new System.Drawing.Size(8, 23);
            this.lblSet.TabIndex = 6;
            this.lblSet.Text = "lblSet";
            this.lblSet.Visible = false;
            // 
            // lblOKinfo
            // 
    this.lblOKinfo.Location = new System.Drawing.Point(248, 168);
            this.lblOKinfo.Name = "lblOKinfo";
            this.lblOKinfo.TabIndex = 7;
            this.lblOKinfo.Text = "lblOKinfo";
            this.lblOKinfo.Visible = false;
            // 
            // lblSetinfo
            // 
            this.lblSetinfo.Location = new System.Drawing.Point(16, 168);
            this.lblSetinfo.Name = "lblSetinfo";
            this.lblSetinfo.TabIndex = 8;
            this.lblSetinfo.Text = "lblOKinfo";
            this.lblSetinfo.Visible = false;
            // 
            // FrmSetLanguage
            // 
            this.AcceptButton = this.BtnOK;
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClIEntSize = new System.Drawing.Size(280, 197);
            this.Controls.Add(this.lblOKinfo);
            this.Controls.Add(this.gBox);
            this.Controls.Add(this.BtnOK);
            this.Controls.Add(this.BtnExit);
            this.Controls.Add(this.lblOK);
            this.Controls.Add(this.lblSet);
            this.Controls.Add(this.lblSetinfo);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FrmSetLanguage";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "FrmSetLanguage";
            this.Load += new System.EventHandler(this.SetLanguageOption_Load);
            this.gBox.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion


        private void SetLanguageOption_Load(object sender, System.EventArgs e)
        {
            DefaultLanguage=Rdla.ReadDefaultLanguages();
            ReadDefaultLanguage Rdela=new ReadDefaultLanguage();   
            Rdela.getNames(this,DefaultLanguage);


            
             ReadAppConfig Racig=new ReadAppConfig();

            IList Languages=Racig.GetLanguageList(DefaultLanguage);

            this.Lboxlang.DataSource=Languages;            
        }

        private void BtnOK_Click(object sender, System.EventArgs e)
        {
           
            if(MessageBox.Show(RbtnTxt+" "+this.lblSet.Text ,this.lblSetinfo.Text,System.Windows.Forms.MessageBoxButtons.OKCancel,System.Windows.Forms.MessageBoxIcon.Information).ToString()=="OK&quo            {
                ReadAppConfig Racig=new ReadAppConfig();
                string Setlang;
                Setlang=Racig.GetChildLanguage(RbtnTxt,DefaultLanguage);
                ReadDefaultLanguage Writelang=new ReadDefaultLanguage();
                Writelang.WriteDefaultLanguage(Setlang);
                MessageBox.Show(this.lblOK.Text,this.lblOKinfo.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
                this.Close();
                Application.Exit();
            }            
        }

        private void Lboxlang_SelectedIndExchanged(object sender, System.EventArgs e)
        {
            RbtnTxt=((ListBox)sender).Text;
        }

        private void BtnExit_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }
    }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved