home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dragfo / dragform.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  2.6 KB  |  80 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Dragging Forms And TextBoxes Demo"
  5.    ClientHeight    =   3120
  6.    ClientLeft      =   1320
  7.    ClientTop       =   1905
  8.    ClientWidth     =   4575
  9.    Height          =   3525
  10.    Left            =   1260
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   3120
  15.    ScaleWidth      =   4575
  16.    Top             =   1560
  17.    Width           =   4695
  18.    Begin TextBox Text1 
  19.       Height          =   1820
  20.       Left            =   1440
  21.       MultiLine       =   -1  'True
  22.       TabIndex        =   0
  23.       Text            =   "Text1"
  24.       Top             =   840
  25.       Width           =   1455
  26.    End
  27.    Begin Label Label1 
  28.       Caption         =   "To drag the textbox hold down the control key and press the left mouse button."
  29.       Enabled         =   0   'False
  30.       Height          =   500
  31.       Left            =   480
  32.       TabIndex        =   1
  33.       Top             =   120
  34.       Width           =   3735
  35.    End
  36. Sub Form_DragDrop (Source As Control, X As Single, Y As Single)
  37.     Call GetCursorPos(CurPos)
  38.     Call ScreenToClient(Form1.hWnd, CurPos)
  39.         NewPosX% = CurPos.X - MyPosX%
  40.         NewPosY% = CurPos.Y - MyPosY%
  41.     Call MoveWindow(TBhWnd, NewPosX%, NewPosY%, TextBoxRect.Right - TextBoxRect.Left, TextBoxRect.Bottom - TextBoxRect.Top, -1)
  42.     Text1.Dragmode = 0
  43.     Text1.Refresh
  44. End Sub
  45. Sub Form_Load ()
  46.     Show
  47.     Text1.SetFocus
  48.     TBhWnd = GetFocus()
  49.     Call GetWindowRect(TBhWnd, TextBoxRect)
  50. End Sub
  51. Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  52.       Call GetCursorPos(CurPos)
  53.       Call ScreenToClient(Form1.hWnd, CurPos)
  54.       MyPosX% = CurPos.X
  55.       MyPosY% = CurPos.Y
  56. End Sub
  57. Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  58.       If Button = Left_Button And Shift = 0 Then
  59.         Call GetCursorPos(CurPos)
  60.         NewPosX% = CurPos.X - MyPosX%
  61.         NewPosY% = CurPos.Y - MyPosY%
  62.         Call SetWindowPos(Form1.hWnd, 0, NewPosX%, NewPosY%, 0&, 0&, SWP_NOSIZE)
  63.       End If
  64. End Sub
  65. Sub Text1_DragDrop (Source As Control, X As Single, Y As Single)
  66.   Form_DragDrop Source, X, Y
  67. End Sub
  68. Sub Text1_KeyDown (KeyCode As Integer, Shift As Integer)
  69.     If Shift = 2 Then
  70.         Call GetCursorPos(CurPos)
  71.         Call ScreenToClient(TBhWnd, CurPos)
  72.         MyPosX% = CurPos.X
  73.         MyPosY% = CurPos.Y
  74.         Text1.Dragmode = 1
  75.     End If
  76. End Sub
  77. Sub Text1_KeyUp (KeyCode As Integer, Shift As Integer)
  78.    Text1.Dragmode = 0
  79. End Sub
  80.