当前位置:编程学习 > VB >>

vb.net拉伸窗体

怎样在VB.NET语言中可以是窗体为None时用户可以拉伸窗体,像QQ一样。
追问:您是不是没理解我的意思……不能拉伸窗体啊,一点拉伸窗体的代码都没有,就一个MsgBox语句嘛……
答案:窗体设置为NONE的话是不能让你拉动窗体的

这个要自己写代码   比如说你在窗体四周拉四个控件  比如Button什么的都可以 点击的时候记录下鼠标的坐标值,然后拖动的时候记录下鼠标位移数据,拖动时可以计算出鼠标位移值,然后加到窗体的大小与坐标点上

 

    Private MouseX As Integer
    Private MouseY As Integer
    Private MainW As Integer
    Private MainH As Integer

 

Private Sub Button101_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button101.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            MouseX = e.X
        End If
    End Sub

    Private Sub Button101_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button101.MouseMove
        If Me.Size.Width <= 5 Then
            Me.Size = New Size(MainW, MainH)
            If Me.Location.X <> 0 Then
                Me.Location = New Point(My.Computer.Screen.Bounds.Size.Width - Me.Size.Width, Me.Location.Y)
            End If
        End If
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.Size = New Size(Me.Size.Width - (MouseX - e.X), Me.Size.Height)
            If Me.Size.Width < 120 Then
                Me.Size = New Size(120, Me.Size.Height)
            End If
        End If
    End Sub

    Private Sub Button102_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button102.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            MouseX = e.X
        End If
    End Sub

    Private Sub Button102_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button102.MouseMove
        If Me.Size.Width <= 5 Then
            Me.Size = New Size(MainW, MainH)
            If Me.Location.X <> 0 Then
                Me.Location = New Point(My.Computer.Screen.Bounds.Size.Width - Me.Size.Width, Me.Location.Y)
            End If
        End If
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.Size = New Size(Me.Size.Width + (MouseX - e.X), Me.Size.Height)
            If Me.Size.Width < 120 Then
                Me.Size = New Size(120, Me.Size.Height)
            End If
        End If
    End Sub

    Private Sub Button103_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button103.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            MouseY = e.Y
        End If
    End Sub

    Private Sub Button103_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button103.MouseMove
        If Me.Size.Height <= 5 Then
            Me.Size = New Size(MainW, MainH)
        End If
        If e.Button = Windows.Forms.MouseButtons.Left And Me.Size.Height >= 400 Then
            Me.Size = New Size(Me.Size.Width, Me.Size.Height - (MouseY - e.Y))
            If Me.Size.Height < 400 Then
                Me.Size = New Size(Me.Size.Width, 400)
            End If
            If Panel2.Size.Height <> 24 And Panel2.Size.Height > 295 Then
                Panel2.Size = New Size(Panel2.Size.Width, Panel2.Size.Height - (MouseY - e.Y))
                If Panel2.Size.Height < 296 Then
                    Panel2.Size = New Size(Panel2.Size.Width, 296)
                End If
            End If
            If Panel2.Location.Y >= 296 Then
                If Panel2.Location.Y > 496 Then
                    Panel2.Location = New Point(Panel2.Location.X, 496)
                Else
                    Panel2.Location = New Point(Panel2.Location.X, Panel2.Location.Y - (MouseY - e.Y))
                End If
                If Panel2.Location.Y < 296 Then
                    Panel2.Location = New Point(Panel2.Location.X, 296)
                End If
            End If
        End If
    End Sub

    Private Sub main_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            MouseX = e.X
           

上一个:VB问题 帮帮忙 谢谢
下一个:关于vb的一个小问题

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,