⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 这里有很多很实用的VB编程案例,方便大家学习VB.
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "移动的窗体"
   ClientHeight    =   2850
   ClientLeft      =   3150
   ClientTop       =   390
   ClientWidth     =   5565
   LinkTopic       =   "Form1"
   ScaleHeight     =   2850
   ScaleWidth      =   5565
   Begin VB.Timer Timer1 
      Interval        =   1
      Left            =   2400
      Top             =   960
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim stepX
Dim stepY

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib "User32" ()
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Private Sub Form_Load()
    stepX = 1
    stepY = 1
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim lngReturnValue As Long
    If Button = 1 Then
        Call ReleaseCapture
        lngReturnValue = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
    End If
End Sub

Private Sub Timer1_Timer()
     frmHt = Me.Height
     frmWd = Me.Width
     frmTp = Me.Top
     frmLt = Me.Left

     scnHt = Screen.Height
     scnWd = Screen.Width

     MoveX = Screen.TwipsPerPixelX * stepX
     MoveY = Screen.TwipsPerPixelY * stepY

     frmLt = frmLt + MoveX
     frmTp = frmTp + MoveY


    If scnWd < frmLt + frmWd Then
         frmLt = scnWd - frmWd
         stepX = -stepX
    End If

    If frmLt < 0 Then
         frmLt = 0
        stepX = -stepX
    End If

    If frmTp < 0 Then
         frmTp = 0
        stepY = -stepY
    End If

    If scnHt < frmHt + frmTp Then
         frmTp = scnHt - frmHt
        stepY = -stepY
    End If

    Me.Height = frmHt
    Me.Width = frmWd
    Me.Left = frmLt
    Me.Top = frmTp
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -