您的位置:首页 > 其它

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

2007-08-18 09:15 483 查看
运行时改变控件大小运行时移动控件MINICAR版

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

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

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: