110,539
社区成员
发帖
与我相关
我的任务
分享
Imports System.Reflection
Imports System.Windows.Forms
Imports System.Resources
Public Class PrintPreviewDialogEx
Inherits System.Windows.Forms.PrintPreviewDialog
Protected WithEvents pToolBar As System.Windows.Forms.ToolBar
Private nInitialImages As Integer
Private AddedButtons As ArrayList
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
pToolBar = Me.ParentToolbar
Dim b As Button = GetCloseButton()
b.Text = "关闭"
Me.Text = "打印预览"
AddHandler pToolBar.ButtonClick, AddressOf AddedButtons_Click
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Public WithEvents AddedButtonsImageList As System.Windows.Forms.ImageList
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(PrintPreviewDialogEx))
Me.AddedButtonsImageList = New System.Windows.Forms.ImageList(Me.components)
'
'AddedButtonsImageList
'
Me.AddedButtonsImageList.ImageSize = New System.Drawing.Size(16, 16)
Me.AddedButtonsImageList.TransparentColor = System.Drawing.Color.Transparent
'
'PrintPreviewDialogEx
'
Me.ClientSize = New System.Drawing.Size(864, 543)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "PrintPreviewDialogEx"
End Sub
#End Region
Public Event AddedButtonsClick As System.Windows.Forms.ToolBarButtonClickEventHandler
Private Sub AddedButtons_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
Dim i As Integer
For i = 0 To AddedButtons.Count - 1
If e.Button Is AddedButtons(i) Then
RaiseEvent AddedButtonsClick(Me, e)
Return
End If
Next
End Sub
Public Sub AddToolBarButtons(ByVal Buttons() As System.Windows.Forms.ToolBarButton)
Dim imgList As ImageList = pToolBar.ImageList
Dim i As Integer
nInitialImages = imgList.Images.Count
AddedButtons = New ArrayList
For i = 0 To AddedButtonsImageList.Images.Count - 1
imgList.Images.Add(AddedButtonsImageList.Images.Item(i))
Next
Dim initw As Integer = 0
For i = 0 To Buttons.GetLength(0) - 1
AddedButtons.Add(Buttons(i))
If Buttons(i).ImageIndex >= 0 Then
Buttons(i).ImageIndex += nInitialImages
End If
pToolBar.Buttons.Add(Buttons(i))
initw += pToolBar.Buttons(pToolBar.Buttons.Count - 1).Rectangle.Width
Next
Dim s As System.Drawing.Size = Me.MinimumSize
s.Width += initw
Me.MinimumSize = s
Dim b As Button = GetCloseButton()
b.Left += initw
End Sub
Private Function GetCloseButton() As Button
Dim fi As FieldInfo = GetType(System.Windows.Forms.PrintPreviewDialog).GetField("closeButton", BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance)
Return CType(fi.GetValue(Me), System.Windows.Forms.Button)
End Function
Public ReadOnly Property ParentToolbar() As System.Windows.Forms.ToolBar
Get
Dim fi As FieldInfo = GetType(System.Windows.Forms.PrintPreviewDialog).GetField("toolBar1", BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance)
Return CType(fi.GetValue(Me), System.Windows.Forms.ToolBar)
End Get
End Property
End Class