Public Class CenterPicture
Inherits System.Windows.Forms.UserControl
Windows 窗体设计器生成的代码
Private m_MapImage As Image
Public 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(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 窗体设计器生成的代码
Private m_MapImage As Image
Public 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(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