求助vb.net 2008 中 printPreviewDialog1预览窗口中如何添加按钮?
就是重绘printPreviewDialog1控件。控件容器中,包含ToolStrip控件。
目的:在ToolStrip控件集合中添加一个ToolStripButton控件按钮。
代码如下:
====================================================
Public Class Form1
'定义相关变量
Private ppdlog1 As New printPreviewDialog '预览控件
Private mytoolstrip1 As New ToolStrip
Private WithEvents myButton1 As New ToolStripButton '新按钮
'------------------创建新按钮的过程
Private Sub CreatemyButton()
Dim c1 As Control
For Each c1 In ppdlog1.Controls
If TypeName(c1) = "ToolStrip" Then
mytoolstrip1 = c1
End If
Next
myButton1.Text = "新按钮"
mytoolstrip1.Items.Add(myButton1)
End Sub
'-----------------------
'在Sub New()中调用如下:
'--------------------------------------------
Public Sub New()
' 此调用是设计器所必需的。
' 在 InitializeComponent() 调用之后添加任何初始化。
CreatemyButton() '创建“新按钮”的过程
End Sub
'----------------------------------------------------
'myButton1的Click过程
'===================
Private Sub myButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("新按钮创建成功!")
'//执行代码.......
End Sub
'===================
'测试一下:
'----------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ppdlog1.Document = PrintDocument1
ppdlog1.ShowDialog()
End Sub
'----------------
End Class
==================================================
效果如图: