我正在使用Winforms,我创建了一个打印预览对话框,以便打印报告。我还在打印预览的不同按钮上创建了自己的打印功能。在打印预览对话框中,还有一个打印按钮。我想在该按钮上创建一个新的处理程序,以便调用我自己的方法。
我设法使用
为我的方法添加了一个处理程序 ((ToolStripButton)((ToolStrip)dlgPreview.Controls[1]).Items[0]).Click += new System.EventHandler(this.button1_Click);
使用此方法虽然调用了两种方法。鉴于我只使用+=
。它创建一个新的处理程序并将其附加到按钮。两个处理程序都被调用。我想我可以使用-=
删除原始处理程序,但是我会在-=
的右侧放置什么?
有没有其他方法可以删除原始处理程序,只有我的个人处理程序?
我正在使用C#
和Winforms
答案 0 :(得分:0)
我设法通过删除那里的特定按钮来实现它,创建一个具有我自己功能的新按钮并将其添加到那里。
使用此代码
ToolStripButton b = new ToolStripButton();
b.ImageIndex = ((ToolStripButton)((ToolStrip)dlgPreview.Controls[1]).Items[0]).ImageIndex;
((ToolStrip)dlgPreview.Controls[1]).Items.Remove(((ToolStripButton)((ToolStrip)dlgPreview.Controls[1]).Items[0]));
b.Visible = true;
((ToolStrip)dlgPreview.Controls[1]).Items.Insert(0, b);
((ToolStripButton)((ToolStrip)dlgPreview.Controls[1]).Items[0]).Click += new System.EventHandler(this.button1_Click);
基本上我是: