c#打开一个excel,加了一个commandbar,按这个加的commandbar开启一个winform窗口,拖动这个窗口出现重影

unimaallan 2009-06-05 11:42:53
我用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;
}

}
}
...全文
96 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
unimaallan 2009-06-08
  • 打赏
  • 举报
回复
都没有人会啊
unimaallan 2009-06-05
  • 打赏
  • 举报
回复
没有人用过吗

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧