无法将类型为“System.Drawing.Bitmap”的对象强制转换为类型“System.ComponentModel.IContainer”。
Private _docement As DocementBase
'打印
Private Sub button3_Click(sender As Object, e As EventArgs) Handles button3.Click
If pictureBox1.Image Is Nothing Then
MessageBox.Show("You Must Load an Image first!")
Return
Else
_docement = New imageDocument(pictureBox1.Image)
End If
_docement.showPrintPreviewDialog()
End Sub
_docement = New imageDocument(pictureBox1.Image)这行报错, '无法将类型为“System.Drawing.Bitmap”的对象强制转换为类型“System.ComponentModel.IContainer”。
其中imageDocument在组件类中有定义
Public Class imageDocument : Inherits DocementBase
Private _Image As Image
Public Property Image() As Image
Get
Return _Image
End Get
Set(value As Image)
_Image = value
If _Image IsNot Nothing Then
If _Image.Size.Width > _Image.Size.Height Then
DefaultPageSettings.Landscape = True
Else
DefaultPageSettings.Landscape = False
End If
End If
End Set
End Property
Public Sub imageDocument()
End Sub
Public Sub imageDocument(image As Image)
Me.Image = image
End Sub