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

相关文章
相关标签/搜索