zoukankan      html  css  js  c++  java
  • dgvHelper,xmlHelper,inputbox(仿vba),Evaluate(vba中函数应用于C#)

    1.在dgv中进行增加、删除、修改行时应针对dt进行操作,然后刷新xml

    2.datagridview中的currentrow未必就是当前选中行

    3.inputbox类

    string sDescription = InputBox.ShowInputBox("请输入表达式的说明!");
        public class InputBox : System.Windows.Forms.Form
        {
            private System.Windows.Forms.Label label1;
            private System.Windows.Forms.TextBox tbData;
            private System.Windows.Forms.Button btnOK;
            private System.Windows.Forms.Button btnCancel;
            private System.Windows.Forms.ToolTip ttpShow;
            private System.ComponentModel.Container components = null;
            private InputBox()
            {
                InitializeComponent();
            }
    
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (components != null)
                    {
                        components.Dispose();
                    }
    
                }
                base.Dispose(disposing);
            }
    
            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.label1 = new System.Windows.Forms.Label();
                this.tbData = new System.Windows.Forms.TextBox();
                this.btnOK = new System.Windows.Forms.Button();
                this.btnCancel = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // label1
                // 
                this.label1.AutoSize = true;
                this.label1.Location = new System.Drawing.Point(13, 13);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(65, 12);
                this.label1.TabIndex = 0;
                this.label1.Text = "在此输入:";
                // 
                // tbData
                // 
                this.tbData.Location = new System.Drawing.Point(84, 10);
                this.tbData.Name = "tbData";
                this.tbData.Size = new System.Drawing.Size(471, 21);
                this.tbData.TabIndex = 1;
                // 
                // btnOK
                // 
                this.btnOK.Location = new System.Drawing.Point(146, 40);
                this.btnOK.Name = "btnOK";
                this.btnOK.Size = new System.Drawing.Size(75, 23);
                this.btnOK.TabIndex = 2;
                this.btnOK.Text = "确定";
                this.btnOK.UseVisualStyleBackColor = true;
                this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
                // 
                // btnCancel
                // 
                this.btnCancel.Location = new System.Drawing.Point(373, 40);
                this.btnCancel.Name = "btnCancel";
                this.btnCancel.Size = new System.Drawing.Size(75, 23);
                this.btnCancel.TabIndex = 2;
                this.btnCancel.Text = "取消";
                this.btnCancel.UseVisualStyleBackColor = true;
                this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
                // 
                // InputBox
                // 
    
                this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
                this.ClientSize = new System.Drawing.Size(567, 75);
                this.ControlBox = false;
                this.Controls.Add(this.btnCancel);
                this.Controls.Add(this.btnOK);
                this.Controls.Add(this.tbData);
                this.Controls.Add(this.label1);
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
                this.Name = "InputBox";
                this.Text = "InputBox";
                this.ResumeLayout(false);
            }
    
            private void btnOK_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void btnCancel_Click(object sender, EventArgs e)
            {
                this.Close();
            }
            /// <summary>
            /// 显示输入框
            /// </summary>
            /// <param name="sHeadText"></param>
            /// <param name="sHistoryText"></param>
            /// <returns></returns>
            public static string ShowInputBox(string sHeadText, string sHistoryText="")
            {
                InputBox inputbox = new InputBox();
                inputbox.StartPosition = FormStartPosition.CenterParent;
                inputbox.Text = sHeadText;
                if (sHistoryText!="")
                {
                    inputbox.tbData.Text = sHistoryText;
                }
                inputbox.ShowDialog();
                return inputbox.tbData.Text;
            }
        }

    4.按excel vba中的公式evaluate计算

        /// <summary>
        /// 利用Excel中VBA的Evaluate方法对字符串进行计算
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static double Cal(this string str)
        {
          var app = new Excel.Application();
          Excel.Workbook workbook = app.Workbooks.Add();
          Excel.Worksheet worksheet = workbook.Worksheets.Add() as Excel.Worksheet;
          var result = worksheet.Evaluate(str);
          app.DisplayAlerts = false;
          app.Quit();
          double data = double.Parse(result.ToString());
          return data;
        }

    5.上项中错误返回的意义

          //-2146826281 =#DIV / 0!
          //-2146826246 - #N / A
          //- 2146826259 =#NAME?
          //-2146826288 =#NULL!
          //-2146826252 =#NUM!
          //-2146826265 =#REF! < -你的!
          //-2146826273 = VALUE!

  • 相关阅读:
    小a和uim之大逃离(dp)
    c++stl应用入门
    tar: 从成员名中删除开头的“/”
    yii中rights安装
    python中operator.itemgetter
    python中时间和时区
    python --那些你应该知道的知识点
    rsync拉取远程文件
    django中时区设置
    django中添加用户
  • 原文地址:https://www.cnblogs.com/swtool/p/7691339.html
Copyright © 2011-2022 走看看