c#打开一个excel,加了一个commandbar,按这个加的commandbar开启一个winform窗口,拖动这个窗口出现重影
我用c#打开一个excel,加了一个commandbar,按这个加的commandbar开启一个winform窗口,拖动这个窗口出现重影,一直找不到原因,打开按按钮就开一个excel,上面加了一个工具列,点工具,就出来winform窗口,拖动,重影
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using System.Reflection;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
namespace 测试工具列
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Office.CommandBar SaverToolBar;
private Office.CommandBarButton StartButton;
private Office.CommandBarButton SettingButton;
private Office.CommandBarButton EnableButton;
private Office.CommandBarComboBox SaverComboBox;
private string SaverKey;
private void button1_Click(object sender, EventArgs e)
{
Excel.Application app1 = new Excel.Application();
app1.Visible = true;
app1.ScreenUpdating = false;
app1.DisplayAlerts = false;
try
{
Excel.Workbook book1 = app1.Workbooks.Add(Type.Missing);
//添加工具栏
SaverToolBar = app1.CommandBars.Add("ExcelSaverToolbar", 1, Type.Missing, true);
SaverToolBar.Visible = true;
//添加工具栏按钮
SettingButton = (Office.CommandBarButton)SaverToolBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true);
SettingButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
SettingButton.Caption = "设置保护密码";
//CzExcel.CzOfficeResources.SetIcon(SettingButton, Globals.Sheet1.imageList1.Images[1]);
SettingButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(SettingButton_Click);
//app1.ScreenUpdating = true;
//app1.Hwnd();
//MessageBox.Show(app1.ScreenUpdating.ToString());
}
catch (Exception exp)
{
MessageBox.Show("程序初始化时发生错误:" + exp.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
app1.ScreenUpdating = true;
}
}
private void SettingButton_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
{
Form2 frm = new Form2();
frm.ShowDialog();
//if (frm.ShowDialog() == DialogResult.OK)
// SaverKey = frm.Key;
}
}
}