运行时改变控件大小运行时移动控件MINICAR版

运行时改变控件大小运行时移动控件MINICAR版

VS2005.net编写,网上找了找,见别人写得挺复杂,自己写了一个. 附件居然不能上传.就把代码发到下面吧,

有个奇怪现象就是,VB6中新建工建,拖个PICTUREBOX框出来,拷入以下代码即可,但VB.NET中是不行的.如MOUSEMOVE事件你必须新建工程,拖个PICTUREBOX控件出来,双击PICTUREBOX,再找到MOUSEMOVE事件,再在代码中添加有效代码,个中何解,我也不知,知道的告诉我一声,QQ182226947,[email protected]

     Public Class Form1
    Dim sX
    Dim sY
    Dim SizeAdj As Boolean

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        sX = e.X
        sY = e.Y
    End Sub
  
  
    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        If (e.X > PictureBox1.Width - 8 And e.Y > PictureBox1.Height - 8) Or SizeAdj = True Then
            PictureBox1.Cursor = Cursors.SizeNWSE
            If e.Button = Windows.Forms.MouseButtons.Left Then
                SizeAdj = True
                PictureBox1.Width = sx + (e.X - sx)
                PictureBox1.Height = sy + (e.Y - sy)
            End If
        Else
            If e.Button = Windows.Forms.MouseButtons.Left Then
                PictureBox1.Left = PictureBox1.Left + (e.X - sx)
                PictureBox1.Top = PictureBox1.Top + (e.Y - sy)
            End If
            PictureBox1.Cursor = Cursors.Default
        End If
    End Sub

  
    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        SizeAdj = False
    End Sub
End Class

猜你喜欢

转载自blog.csdn.net/minicar1388/article/details/1749319