ÔÚÇ°ÃæµÄÎÄÕÂÖУ¬Ìáµ½¹ýÔÚvb.netÖÐʵÏÖpictureboxÖÐͼƬÍ϶¯£¬ÒÔ¼°¿Ø¼þÊý×é·½ÃæµÄ¶«Î÷¡£
ÒòΪÏîÄ¿ÐèÒª£¬ÎÒҪʵÏÖµÄÊÇ£¬Í¼Æ¬ÉÏÓи÷¸öÕ¾µãµÄÃû³Æ£¬ÎÒҪʵÏÖµã»÷ÏàÓ¦µÄÃû³Æ£¬½øÈëÕ¾µã£¬²é¿´ÏàÓ¦µÄÐÅÏ¢¡£ÎÒ²ÉÈ¡µÄÊÇÔÚͼƬÉÏ·ÅһϵÁеÄlabel£¬È»ºóµã»÷label£¬½øÈëÏàÓ¦µÄÕ¾µã£¬ÕâÑù¾ÍÓöµ½ÁËÒ»¸öÎÊÌ⣬ҪʵÏÖÔÚÍ϶¯Í¼Æ¬µÄͬʱ£¬ËùÓеÄlabelҲͬ²½Í϶¯¡£
ÏÂÃæµÄ´úÂëʵÏÖÁËÕâ¸ö¹¦ÄÜ£º
Imports System.Drawing
Namespace WinForm.Main
Public Class MainWindow
Inherits System.Windows.Forms.Form
---- " Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë "---
Public Sub New()
MyBase.New()
'¸Ãµ÷ÓÃÊÇ Windows ´°ÌåÉè¼ÆÆ÷Ëù±ØÐèµÄ¡£
InitializeComponent()
'ÔÚ InitializeComponent() µ÷ÓÃÖ®ºóÌí¼ÓÈκγõʼ»¯
Me.WindowState = Windows.Forms.FormWindowState.Maximized
loadTree()
Me.L_USER_CONTENT.Text = myForm.LogInUser.get_UserName
'µÃµ½pictureboxµÄ³õʼλÖÃ×ø±ê
Me.m_Leftx = Me.PictureBox1.Location.X
Me.m_Lefty = Me.PictureBox1.Location.Y
'µÃµ½Í¼Æ¬µÄËõ·ÅÂÊ
Me.m_StrecthX = Me.PictureBox1.Image.Size.Width / Me.PictureBox1.Size.Width
Me.m_StrecthY = Me.PictureBox1.Image.Size.Height / Me.PictureBox1.Size.Height
'Ìí¼ÓlabelË«»÷µÄ°ó¶¨
BindArray()
End Sub
------------- Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë----------------------
'´¦ÀíͼƬÍ϶¯
Private m_Leftx As Integer = 152
Private m_Lefty As Integer = 0
Dim m_MousePosX As Integer
Dim m_MousePosY As Integer
Dim m_DriftX As Integer
Dim m_DriftY As Integer
'Ëõ·ÅÂÊ
Dim m_StrecthX As Double
Dim m_StrecthY As Double
'labelÆðʼÏà¶ÔÓÚpictureboxµÄλÖÃ
Dim m_L_GW_RY_X As Integer
Dim m_L_GW_RY_Y As Integer
Dim m_L_STATION_ZF_X As Integer
Dim m_L_STATION_ZF_Y As Integer
'ÊÇ·ñµÚÒ»´ÎËõ·Å
Dim m_L_FIRST As Boolean = True
'´¦Àílabel
Dim Labels As New Common.LabelArray(Me)
'µ±Êó±ê°´ÏÂʱ£¬½«Êó±ê±ä³ÉÊÖÐΣ¬²¢ÇҼǼϵ±Ç°Êó±êµÄλÖÃ
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Me.Cursor = System.Windows.Forms.Cursors.Hand
m_MousePosX = e.X
m_MousePosY = e.Y
GetLabelPositon()
End Sub
'¸ù¾ÝÆ«ÒÆÁ¿¼ÆËã³öµÄͼƬλÖã¬ÖػͼƬ
Private Sub picturemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim myBit As New System.Drawing.Bitmap(PictureBox1.Image)
Dim myPicGrh As System.Drawing.Graphics = Me.PictureBox1.CreateGraphics
myPicGrh.Clear(Me.PictureBox1.BackColor)
myPicGrh.DrawImageUnscaled(myBit, m_Leftx - 152, m_Lefty)
StretchLabel()
myBit.Dispose()
myPicGrh.Dispose()
End Sub
'´¦ÀíÊó±ê°´¼ü̧ÆðµÄʼþ£¬¸ù¾ÝÊó±ê°´ÏÂʱ±£´æµÄÊó±êλÖ㬺͵±Ç°Êó±êµÄλÖ㬼ÆËãÊó±êÒÆ¶¯Æ«ÒÆÁ¿£¬½è´Ëµ÷ÓÃÒÆ¶¯Í¼Æ¬µÄº¯Êý£¬Òƶ¯Í¼Æ¬
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
m_DriftX = m_MousePosX - e.X
m_DriftY = m_MousePosY - e.Y
m_Leftx = m_Leftx - m_DriftX
m_Lefty = m_Lefty - m_DriftY
picturemove(sender, e)
Me.Cursor = System.Windows.Forms.Cursors.Arrow
End Sub
'½«¹ÜÍøÍ¼ÉϵÄÕ¾µãµÄlabelÓÃÒ»¸öʼþÀ´´¦Àí£¬´¦Àí֮ǰÐèÒª°ó¶¨
Public Sub BindArray()
Labels.AddItem(Me.L_GW_RY)
Labels.AddItem(Me.L_STATION_ZF)
End Sub
'µÃµ½labelµÄÆðʼÏà¶ÔÓÚpictureµÄλÖÃ
Public Sub GetLabelPositon()
m_L_GW_RY_X = (Me.L_GW_RY.Location.X - Me.PictureBox1.Location.X) * Me.m_StrecthX + Me.PictureBox1.Location.X
m_L_GW_RY_Y = Me.L_GW_RY.Location.Y * Me.m_StrecthY
m_L_STATION_ZF_X = (Me.L_STATION_ZF.Location.X - Me.PictureBox1.Location.X) * Me.m_StrecthX + Me.PictureBox1.Location.X
m_L_STATION_ZF_Y = Me.L_STATION_ZF.Location.Y * Me.m_StrecthY
End Sub
'¸ù¾ÝpictureµÄλÖÃÖØ»ælabel
Public Sub StretchLabel()
If m_L_FIRST = True Then
Me.L_GW_RY.Font = New System.Drawing.Font("ËÎÌå", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
L_GW_RY.SetBounds(Me.m_L_GW_RY_X - m_DriftX, Me.m_L_GW_RY_Y - m_DriftY, L_GW_RY.Width * Me.m_StrecthX, L_GW_RY.Height * Me.m_StrecthY)
Me.L_STATION_ZF.Font = New System.Drawing.Font("ËÎÌå", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
L_STATION_ZF.SetBounds(Me.m_L_STATION_ZF_X - m_DriftX, Me.m_L_STATION_ZF_Y - m_DriftY, L_STATION_ZF.Width * Me.m_StrecthX, L_STATION_ZF.Height * Me.m_StrecthY)
Else
If ((L_GW_RY.Location.X - m_DriftX) < Me.PictureBox1.Location.X) Or ((L_GW_RY.Location.X - m_DriftX + L_GW_RY.Size.Width) > (Me.PictureBox1.Size.Width)) Then
L_GW_RY.Visible = False
Else
L_GW_RY.Visible = True
End If
If (L_STATION_ZF.Location.X - m_DriftX) < Me.PictureBox1.Location.X Or (L_STATION_ZF.Location.X - m_DriftX + L_STATION_ZF.Size.Width) > (Me.PictureBox1.Size.Width) Then
L_STATION_ZF.Visible = False
Else
L_STATION_ZF.Visible = True
End If
L_GW_RY.SetBounds(L_GW_RY.Location.X - m_DriftX, L_GW_RY.Location.Y - m_DriftY, L_GW_RY.Width, L_GW_RY.Height)
L_STATION_ZF.SetBounds(L_STATION_ZF.Location.X - m_DriftX, L_STATION_ZF.Location.Y - m_DriftY, L_STATION_ZF.Width, L_STATION_ZF.Height)
End If
m_L_FIRST = False
End Sub
End Class
End Namespace

