WinForm下的TabControl控件


一、TabControl控件介紹

TabControl實現的具體效果:

 

在實際工作中,我是這么用TabControl控件,實現切換頁面效果。比如要實現某個界面進行操作,然后還要查看一下日志,就可以使用這個TabControl控件,來實現。

 

OpenFileDialog控件的使用:

這個控件一般拖放在最下方。一般用於打開文件,瀏覽。比如要在文件路徑下,導入一個excel文件,先點擊瀏覽按鈕,觸發后彈出文件篩選器

然后,文件路徑的文本框會顯示該文件的具體路徑,然后進行導入操作。

可以在導入的同時,將出錯的信息寫到日志里面,可以進行查看日志。

首先要給頁面定義這幾個事件:

  • 查詢事件
  • 頁面加載事件
  • 瀏覽事件
  • 日志記錄。

查詢事件:

#region SetData()
        private void SetData()
        {
            if (txbBKVSL.Text.Trim() != null && txbBKVOY.Text.Trim() != null && txbBKFLG2.Text.Trim() != null)
            {
                DateTime dtBegin = MessageProcess.GetDataWait();
                ParmArray parmArray = new ParmArray();
                parmArray.Add("ADotBKVSL", this.txbBKVSL.Text.ToString().Trim());//船代碼
                parmArray.Add("ADotBKVOY", this.txbBKVOY.Text.ToString().Trim());//航次
                parmArray.Add("ADotBKFLG2", this.txbBKFLG2.Text.ToString().Trim());//代理
                DataSet ds = lnflibSystem.GetImportExcelData(parmArray);
                OperateUI.AddSelectColumn(ds);
                if (!OperateUI.HaveData(ds))
                {
                    MessageBox.Show("無效的船代碼,航次,代理!");
                    return ;
                }
                ControlMethord.GridInfoShow(dtBegin,ds,grdList);
            }
        }
        #endregion

        #region 查詢
        private void ExportExcelExport_EventQuery(object sender, EventArgs e)
        {
            SetData();
        }
        #endregion
View Code

頁面加載事件:初始化頁面用

#region 頁面加載
        private void ExportExcelExport_Load(object sender, EventArgs e)
        {
            grdList.InitPropertiy();
        }
        #endregion
View Code

瀏覽事件:

#region 瀏覽文件
        private void ImportExcelImport_EventDetail(object sender, EventArgs e)
        {
            if (textFilePath.Text.Length > 0)
            {
                openFileDialog1.FileName = textFilePath.Text;
            }
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textFilePath.Text = openFileDialog1.FileName;
            }
        }
        #endregion
View Code

日志記錄方法:

        #region 日志記錄

        #region 日志回調函數
        /// <summary>
        /// 日志回調函數
        /// </summary>
        /// <param name="text"></param>
        private delegate void SetLogTextCallback(string text);
        #endregion

        #region 寫日志
        /// <summary>
        /// 寫日志
        /// </summary>
        /// <param name="strMsg"></param>
        private void SetLogText(string strMsg)
        {
            // InvokeRequired需要比較調用線程ID和創建線程ID
            // 如果它們不相同則返回true
            if (this.tbInfo.InvokeRequired)
            {
                SetLogTextCallback d = new SetLogTextCallback(SetLogText);
                this.Invoke(d, new object[] { strMsg });
            }
            else
            {
                tbInfo.Text = tbInfo.Text + strMsg;
            }
        }
        #endregion

        #region 日志信息
        private void LogMessage(string strMsg)
        {
            strMsg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + strMsg + System.Environment.NewLine;
            MessageProcess.InfoShow(strMsg);
            SetLogText(strMsg);
        }
        #endregion

        #endregion
View Code

 

by author:Foreordination

2018-02-01 10:19:41


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM