整理c# 不常用但有用代码

整理c# 不常用但有用代码


1.winform窗体右键菜单打开其他窗体

 private void contextMenuStripHandler_Click(object sender, EventArgs e)
        {

            ContextMenuStrip menu = sender as ContextMenuStrip;

            foreach (ToolStripMenuItem item in menu.Items)
            {
                if (item.Selected)
                {
                    int index = dgInfo.CurrentCell.RowIndex;
                    Object[] parameters = new Object[2]; // 定义构造函数需要的参数,所有参数都必须为Object
                    parameters[0] = dgInfo.Rows[index].Cells["orderNo"].Value;
                    parameters[1] = dgInfo.Rows[index].Cells["remark"].Value;

                    Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集 
                    var newForm = (Form)assembly.CreateInstance("QZJP.Agent.Platform.AutoTicket." + item.ToolTipText, true, System.Reflection.BindingFlags.Default,
null, parameters, null, null);
                    newForm.StartPosition = FormStartPosition.CenterScreen;
                    newForm.Show();
                }
            }
        }

原文地址:https://www.cnblogs.com/bangejingting/p/5684013.html