WinForm下的TabControl控件

1、TabControl控件介紹

TabControl實現的具體效果:ide

 

在實際工做中,我是這麼用TabControl控件,實現切換頁面效果。好比要實現某個界面進行操做,而後還要查看一下日誌,就能夠使用這個TabControl控件,來實現。函數

 

OpenFileDialog控件的使用:ui

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

而後,文件路徑的文本框會顯示該文件的具體路徑,而後進行導入操做。spa

能夠在導入的同時,將出錯的信息寫到日誌裏面,能夠進行查看日誌。線程

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

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

查詢事件:日誌

#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

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

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

瀏覽事件: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

相關文章
相關標籤/搜索