Public Class CenterPictureClass CenterPicture
Inherits System.Windows.Forms.UserControl
Windows 窗体设计器生成的代码#Region " Windows 窗体设计器生成的代码 "
Public Sub New()Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'UserControl 重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose()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
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
'
'CenterPicture
'
Me.Name = "CenterPicture"
Me.Size = New System.Drawing.Size(272, 192)
End Sub
#End Region
Private m_MapImage As Image
Public Property 图像()Property 图像() As Image
Get
Return m_MapImage
End Get
Set(ByVal Value As Image)
m_MapImage = Value
Me.Invalidate()
End Set
End Property
Dim m_BasePoint As PointF
Dim m_Size As SizeF
Dim m_Scale As Double
Private Sub UserControl1_Paint()Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If Not (m_MapImage Is Nothing) Then
Dim mapScale As Double = m_MapImage.Size.Height / m_MapImage.Size.Width
Dim myScale As Double = Me.Size.Height / Me.Size.Width
If mapScale > myScale Then
m_BasePoint = New PointF(CSng((Me.Size.Width - Me.Size.Height / mapScale) / 2), 0)
m_Size = New SizeF(CSng(Me.Size.Height / mapScale), CSng(Me.Size.Height))
m_Scale = CSng(Me.Size.Height / m_MapImage.Size.Height)
Else
m_BasePoint = New PointF(0, CSng((Me.Size.Height - Me.Size.Width * mapScale) / 2))
m_Size = New SizeF(CSng(Me.Width), CSng(Me.Size.Width * mapScale))
m_Scale = CSng(Me.Size.Width / m_MapImage.Size.Width)
End If
e.Graphics.DrawImage(m_MapImage, New RectangleF(m_BasePoint, m_Size))
End If
End Sub
End Class
Inherits System.Windows.Forms.UserControl
Windows 窗体设计器生成的代码#Region " Windows 窗体设计器生成的代码 "
Public Sub New()Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'UserControl 重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose()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
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
'
'CenterPicture
'
Me.Name = "CenterPicture"
Me.Size = New System.Drawing.Size(272, 192)
End Sub
#End Region
Private m_MapImage As Image
Public Property 图像()Property 图像() As Image
Get
Return m_MapImage
End Get
Set(ByVal Value As Image)
m_MapImage = Value
Me.Invalidate()
End Set
End Property
Dim m_BasePoint As PointF
Dim m_Size As SizeF
Dim m_Scale As Double
Private Sub UserControl1_Paint()Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If Not (m_MapImage Is Nothing) Then
Dim mapScale As Double = m_MapImage.Size.Height / m_MapImage.Size.Width
Dim myScale As Double = Me.Size.Height / Me.Size.Width
If mapScale > myScale Then
m_BasePoint = New PointF(CSng((Me.Size.Width - Me.Size.Height / mapScale) / 2), 0)
m_Size = New SizeF(CSng(Me.Size.Height / mapScale), CSng(Me.Size.Height))
m_Scale = CSng(Me.Size.Height / m_MapImage.Size.Height)
Else
m_BasePoint = New PointF(0, CSng((Me.Size.Height - Me.Size.Width * mapScale) / 2))
m_Size = New SizeF(CSng(Me.Width), CSng(Me.Size.Width * mapScale))
m_Scale = CSng(Me.Size.Width / m_MapImage.Size.Width)
End If
e.Graphics.DrawImage(m_MapImage, New RectangleF(m_BasePoint, m_Size))
End If
End Sub
End Class