如何在拖动另一个图片框时隐藏图片框?

时间:2014-06-30 18:35:25

标签: vb.net-2010

所以我确定了在Windows窗体周围拖动图片框的功能。当它被拖放到另一张照片上时,我需要它隐藏起来。我尝试了一些方法,但似乎没有任何方法,我现在回到第一个方面,我唯一的代码就是我可以在图片框周围移动图片框。

2 个答案:

答案 0 :(得分:0)

我解决了你的问题

表格应如何显示

enter image description here

以下是我制定的准则:

    Private Sub CheckTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckTimer.Tick
    CheckTimer.Stop()
    CheckTimer.Interval = 1
    If PictureBox2.Location = New System.Drawing.Point(TextBox1.Text, TextBox2.Text) Then
        PictureBox2.Visible = False
    End If
    CheckTimer.Start()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    TextBox1.Text = PictureBox1.Location.X
    TextBox2.Text = PictureBox1.Location.Y
    CheckTimer.Start()
End Sub

希望此代码对您有所帮助。

答案 1 :(得分:0)

我制作了比旧版更好的代码,试试吧。

以下是表格的外观:

enter image description here

这是代码:

Public Class Form1
Dim Point As New Point
Dim X, Y As Integer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Timer1.Stop()
    Timer1.Interval = 1
    Point = Cursor.Position
    PictureBox2.Location = New System.Drawing.Point(Point.X - X, Point.Y - Y)
    Timer1.Start()
End Sub

Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown
    X = Cursor.Position.X - PictureBox2.Location.X
    Y = Cursor.Position.Y - PictureBox2.Location.Y
    Timer1.Start()
End Sub

Private Sub PictureBox2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseUp
    Timer1.Stop()
    If PictureBox2.Location.X < PictureBox1.Size.Width Then
        PictureBox2.Visible = False
    End If
End Sub

结束班

我希望这段代码对你有用。