vb.net里面禁止窗体移动的代码。没试过子窗体是否有效。主要通过拦截窗体的LocationChanged事件,使窗体的位置不发生变化
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Private startPositionX As Integer '存储窗体X轴坐标 Private startPositionY As Integer '存储窗体Y轴坐标 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load startPositionX = Me.Location.X '获取X坐标 startPositionY = Me.Location.Y '获取Y坐标 AddHandler Me.LocationChanged, New EventHandler(AddressOf Form1_LocationChanged) End Sub Private Sub Form1_LocationChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Form1.LocationChanged '拦截窗体移动事件 Me.Location = New Point(Me.startPositionX, Me.startPositionY) '定义窗体新的位置为原先定义的X、Y坐标 End Sub |
原文链接:vb.net禁止窗体移动代码,转载请注明来源!