我在表单上有一个用户可以拖动的图片框。这是Top&左侧属性被保存,因此当表格关闭时,图片框出现在同一个地方。再次开放。
除非图像中有很多白色或空白区域,并且用户将远离窗体的光圈推到负值,否则图像将正常工作,一旦可见的图像设置为假和放大,图像将不会重新出现;然后再次成真或表格已关闭&重新开放。除非值大于(技术上小于)-100,否则负值通常都可以。我还没有找到确切的限制。我已经看到问题发生在-100顶部和-250+左右。
我想弄清楚为什么会这样。据我所知,顶部和左侧属性存储为一个整数,可以容纳大约-2亿+所以我不相信这是问题。
有什么想法吗?
这就是图片框的移动方式:
Private Sub picBox_MouseDown(sender As Object, e As MouseEventArgs) Handles picBox.MouseDown
off.X = MousePosition.X - sender.Left
off.Y = MousePosition.Y - sender.Top
End Sub
Private Sub picBox_MouseMove(sender As Object, e As MouseEventArgs) Handles picBox.MouseMove
If e.Button = MouseButtons.Left Then
sender.Left = MousePosition.X - off.X
sender.Top = MousePosition.Y - off.Y
End If
End Sub
这是Top&左侧属性已保存:
Private Sub picBox_LocationChanged(sender As Object, e As EventArgs) Handles picBox.LocationChanged
If globalMode > "" Then
'If picBox.Top < 0 Then picBox.Top = 0
'If picBox.Left < 0 Then picBox.Left = 0
MainForm.overlays.Item(globalMode & "PicLocTop") = picBox.Top
MainForm.overlays.Item(globalMode & "PicLocLeft") = picBox.Left
End If
End Sub
这就是从表单中删除图片框的方式:
Private Sub closeContent()
lblContent.Visible = False
picBox.Visible = False
picBox.ImageLocation = ""
picBox.Top = 12
picBox.Left = 28
Me.Height = origH
Me.Width = origW
lblContent.Top = 44
lblContent.Left = 92
End Sub
这就是图片框重现的方式:
Private Sub openContent(mode As String)
lblContent.Visible = True
picBox.Visible = True
If MainForm.overlays.Item(mode & "Image") > "" Then
picBox.ImageLocation = MainForm.overlays.Item(mode & "Image")
End If
If Not IsNothing(MainForm.overlays.Item(mode & "PicLocTop")) Then
picBox.Top = CInt(MainForm.overlays.Item(mode & "PicLocTop"))
End If
If Not IsNothing(MainForm.overlays.Item(mode & "PicLocLeft")) Then
picBox.Left = CInt(MainForm.overlays.Item(mode & "PicLocLeft"))
End If
If Not IsNothing(MainForm.overlays.Item(mode & "H")) Then
Me.Height = CInt(MainForm.overlays.Item(mode & "H"))
End If
If Not IsNothing(MainForm.overlays.Item(mode & "W")) Then
Me.Width = CInt(MainForm.overlays.Item(mode & "W"))
End If
If Not IsNothing(MainForm.overlays.Item(mode & "ContentTop")) Then
lblContent.Top = CInt(MainForm.overlays.Item(mode & "ContentTop"))
End If
If Not IsNothing(MainForm.overlays.Item(mode & "ContentLeft")) Then
lblContent.Left = CInt(MainForm.overlays.Item(mode & "ContentLeft"))
End If
If MainForm.overlays.Item("apiBGr") > "" Or MainForm.overlays.Item("apiBGg") > "" Or MainForm.overlays.Item("apiBGb") > "" Then
Me.BackColor = Color.FromArgb(Val(MainForm.overlays.Item("apiBGr")), Val(MainForm.overlays.Item("apiBGg")), Val(MainForm.overlays.Item("apiBGb")))
End If
lblContent.ForeColor = Color.FromArgb(Val(MainForm.overlays.Item(mode & "FontR")), Val(MainForm.overlays.Item(mode & "FontG")), Val(MainForm.overlays.Item(mode & "FontB")))
If MainForm.overlays.Item(mode & "FontBGr") = "" And MainForm.overlays.Item(mode & "FontBGg") = "" And MainForm.overlays.Item(mode & "FontBGb") = "" Then
lblContent.BackColor = Color.Transparent
Else
lblContent.BackColor = Color.FromArgb(Val(MainForm.overlays.Item(mode & "FontBGr")), Val(MainForm.overlays.Item(mode & "FontBGg")), Val(MainForm.overlays.Item(mode & "FontBGb")))
End If
SetFont(mode)
If MainForm.overlays.Item(mode & "ImageResize") = "True" Then
picBox.SizeMode = PictureBoxSizeMode.StretchImage
Else
picBox.SizeMode = PictureBoxSizeMode.AutoSize
End If
lblContent.Refresh()
picBox.Refresh()
End Sub