Esempio n. 1
0
 /// <summary>
 /// 添加控件
 /// <para>外部控件</para>
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void toolMenuItems_adds_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog of = new OpenFileDialog())
     {
         of.Filter = "net程序集(*.dll)|*.dll";
         if (of.ShowDialog() == DialogResult.OK)
         {
             Assembly assem = null;
             try
             {
                 assem = Assembly.LoadFile(of.FileName);
             }
             catch
             {
                 MessageBox.Show("不可识别程序集!");
             }
             if (assem != null)
             {
                 using (AddControlDialog add = new AddControlDialog())
                 {
                     add.Assembly = assem;
                     if (add.ShowDialog() == DialogResult.OK)
                     {
                         //ToolStripMenuItem i = new ToolStripMenuItem(add.CtrlName);
                         //i.Tag = add.FullName + "/" + of.FileName;
                         ////toolStrip1.Items.Insert(toolStrip1.Items.Count - 1, i);
                         //i.MouseDown += new MouseEventHandler(toolStripButton10_MouseDown);
                         //添加菜单
                         UserControls.ToolMenuItems toolMenuItems = new UserControls.ToolMenuItems();
                         toolMenuItems.ToolImage  = Properties.Resources.tools_settings_24px;
                         toolMenuItems.ToolName   = add.FullName;
                         toolMenuItems.ToolTag    = add.FullName + "/" + of.FileName;
                         toolMenuItems.ToolTip    = "从外部加载的.net控件\n位置:" + of.FileName;
                         toolMenuItems.Size       = new Size(136, 22);
                         toolMenuItems.Anchor     = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                         toolMenuItems.MouseDown += new MouseEventHandler(toolMenuItems_MouseDown);
                         if (LastAddToolsLocation == new Point(-1, -1))
                         {
                             LastAddToolsLocation = new Point(toolMenuItems_adds.Location.X, toolMenuItems_adds.Location.Y + 23);
                         }
                         else
                         {
                             LastAddToolsLocation = new Point(LastAddToolsLocation.X, LastAddToolsLocation.Y + 23);
                         }
                         toolMenuItems.Location = LastAddToolsLocation;
                         this.panel_tools_cus.Controls.Add(toolMenuItems);//从Panel容器中添加
                         toolMenuItems.BringToFront();
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 拖拽控件
        /// </summary>
        private void toolMenuItems_MouseDown(object sender, MouseEventArgs e)
        {
            ToolStripItem ctrl = sender as ToolStripItem;

            if (ctrl != null)
            {
                string[] strs = { ctrl.Tag == null ? "" : ctrl.Tag.ToString(), ctrl.Text };
                DoDragDrop(strs, DragDropEffects.Copy);
            }
            else
            {
                UserControls.ToolMenuItems tool = sender as UserControls.ToolMenuItems;
                if (tool != null)
                {
                    string[] strs = { tool.Tag == null ? "" : tool.Tag.ToString(), tool.Text };
                    DoDragDrop(strs, DragDropEffects.Copy);
                }
            }
        }